sql - Group by Multiple columns and case statement -
i have present orderdata group month , card type year this:
month cardtype order_cnt 201201 amex 10,835 201201 disc 6,542 201201 mc 2,675 201202 amex 66,817 201202 disc 36,581 201202 mc 165,683
the table can data has orders each day of month. used following sql group order count each day of month card type:
(
select cardtype,orderdate,count (distinct(orderserialno)) tablename orderdate between '01-jan-2012' , '31-dec-2012' group cardtype,orderdate
)
now need present data in above form using case statement have group month, not able that. can please help.
thanks
to group month can use:
sqlserver:
group year(datefield)+month(datefield)
or oracle:
group to_char(datefield, 'year') + to_char(datefield, 'month')
so query:
select cardtype,count (distinct(orderserialno)),year(datefield)+month(datefield) order_date tablename orderdate between '01-jan-2012' , '31-dec-2012' group cardtype,year(datefield)+month(datefield)
Comments
Post a Comment