We help IT Professionals succeed at work.

Im trying to get a total for the following query

jknj72
jknj72 asked
on
132 Views
Last Modified: 2015-06-10
I reaize that its just counting for every row but is there a way I can put a Select around this to get the SUM of nbr_risks or even better to include the SUM in the resultset ?

select sum(prem) sum_prem
          , count(1) nbr_risks  --Trying to get a total of this
           , range_row from
           ( select  prem
                   , case when (nvl(prem,0) <= 499) then 1
                          when (nvl(prem,0) <= 999) then 2
                          when (nvl(prem,0) <= 4999) then 3
                          else 4
                     end as range_row
             from (
                      SELECT nvl(per.tot_est_std_prem,0) prem  --supposed to include exp const and PPAP, but not second injury or uninsur emp surcharges
                      from coverage cov inner join cov_period per on (cov.carrid = per.carrid and cov.polnbr = per.polnbr and cov.cov_effdt = per.cov_effdt)                      
                      where cov.plan_ind = 2
                      and ( (cov.status in ('A','R','E','N')  
                             and cov.cov_expdt between trunc(TO_DATE('01-SEP-2014','dd-mon-rrrr'), 'mm') and last_day(TO_DATE('01-SEP-2014','dd-mon-rrrr')))
                      or (cov.status = 'C' and cov.status_dt > cov.cov_effdt
                          and cov.status_dt between trunc(TO_DATE('01-SEP-2014','dd-mon-rrrr'), 'mm') and last_day(TO_DATE('01-SEP-2014','dd-mon-rrrr'))
                          )
                      )
                    )
            )
      group by range_row
      order by range_row;
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
When I have a query that Im going to try and write, I post the question and then try to figure it out on my own while I wait. Im happy to say that I had almost identical code that you sent. Hey man Im getting there Slight...Thanks again as always!!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.