Thursday, December 23, 2010

Grop by with multiple aggregate clauses

Multiple aggregate clauses in a group by..

select mstr_date
,sum((case when bs ='S' then -1 else 1 end )*quantity) as qty_sum
,sum((case when bs ='S' then -1 else 1 end)*orig_face) as orig_face_sum
,count(*)
from table_name
where column='xxxx'
group by mstr_date
order by mstr_date

I never tried this until now. Very interesting.

No comments: