oracle query

Select 
            decode(hsc.hospital_system_code,'BCA','BCA','MISC OTHER','OTHERS','ALL') as groups,upper(c.name) as name,	
			NVL(SUM(CASE WHEN vp.inv_product_type = 'RBC' THEN id.order_qty ELSE 0 END ), 0) RBC, 
			NVL(SUM(CASE WHEN vp.inv_product_type = 'LRBC' THEN id.order_qty ELSE 0 END), 0) LRBC,		
			NVL(SUM(CASE WHEN vp.inv_product_type in ('PHER','VPHER', 'LPHER') THEN id.order_qty ELSE 0 END), 0) PHERESIS,		
			NVL(SUM(CASE WHEN vp.inv_product_type in ('PFFP','FP24','FFP') THEN id.order_qty ELSE 0 END), 0) FFPUTIL,	
			NVL(SUM(CASE WHEN vp.inv_product_type = 'CPPLS' THEN id.order_qty ELSE 0 END), 0) CPPUTIL,	
			NVL(SUM(CASE WHEN vp.inv_product_type = 'CRYO' THEN id.order_qty ELSE 0 END), 0) CRYO,	
			NVL(SUM(CASE WHEN vp.inv_product_type = 'POCRY' THEN id.order_qty ELSE 0 END), 0) POCRY,
			NVL(SUM(CASE WHEN vp.inv_product_type = 'CPPLS' THEN id.order_qty ELSE 0 END), 0) OTHERS       
from    invoice_header ih,
        invoice_detail id,
		item_profile ip,
		customers@plab.world c,
		valid_products@plab.world vp,
		hospital_system_cust hsc,
		hospital_system hs
where id.invoice_number = ih.invoice_number
and   id.item_id = ip.item_id
and   ip.item_type in ('P')
and    c.customer_id not in ('WAD-RD0018','WAD-MG0076')
and   ih.customer_id = c.customer_id
and   hsc.customer_id = c.customer_id
and   hsc.hospital_system_code = hs.hospital_system_code
and   trunc(ih.invoice_date) between  '01-jun-2015' and '30-jun-2015'
and id.item_id = vp.product_code
and hosp_usage = 'Y'
group by hsc.hospital_system_code,c.name
order by 1,2

Open in new window


The ones marked in colors have to come as a group. Is there a way to group them when I run the report?
Report-for-Ann.xls
LVL 6
anumosesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sdstuberCommented:
what do you mean by "group them"

sort those rows so they are sequential in the list?
sum them into a single row?
0
anumosesAuthor Commented:
No. I need the customers to come one below the other.

ALL      ADVOCATE SHERMAN HOSPITAL      0      197      67      74      0      0      16      0
ALL      CHRIST MEDICAL CENTER - ADVOCATE      0      0      11      0      0      0      0      0
ALL      LUTHERAN GENERAL HOSPITAL-ADVOCATE      0      10      9      0      0      0      0      0


Like this
0
sdstuberCommented:
so you mean this

>>>  sort those rows so they are sequential in the list


Since there is nothing in your results that identifies your groups other than your manual color coding, you'll need to manually construct an arbitrary ordering criteria.  


ORDER BY CASE
             WHEN name IN
                      ('ADVOCATE SHERMAN HOSPITAL',
                       'CHRIST MEDICAL CENTER - ADVOCATE',
                       'LUTHERAN GENERAL HOSPITAL-ADVOCATE')
             THEN
                 1
             WHEN name IN ('DIVISION OF HEMATOLOGY & ONCOLOGY(RUSH)', 'OAK PARK HOSPITAL')
             THEN
                 2
             WHEN name IN
                      ('EDWARD HOSPITAL AND HEALTH SERVICES', 'EDWARD PLAINFIELD OUTPATIENT CENTER')
             THEN
                 3
             WHEN name IN
                      ('PINNACLE HEALTHCARE,LLC',
                       'PROVENA ST.MARY''S HOSPITAL',
                       'VIBRA HOSPITAL OF NORTHWESTERN INDIANA,LLC')
             THEN
                 4
             ELSE
                 5
         END,
         1,
         2
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
anumosesAuthor Commented:
I did not want to add another column in the database to group them. So asked if that is possible on the fly. Now get your answer. This is what I thought
0
anumosesAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.