Grouping Totals by non standard quarters in MySQL -
i have simple table includes seller, buyer, transaction date, , total.
i want sum transactions each seller quarters on given year. quarters begin on june 1 , end on may 31.
i know how sum seller given date range, can't figure out how multiple quarters.
i like
seller q1total q2total q3total q4total
seems should simple i'm struggling figure out.
you can conditional aggregation:
select seller, sum(case when transactiondate between '20150601' , '20150831' amount else 0 end) q1amount, sum(case when transactiondate between '20150901' , '20151231' amount else 0 end) q2amount, sum(case when transactiondate between '20160101' , '20160229' amount else 0 end) q3amount, sum(case when transactiondate between '20160301' , '20160531' amount else 0 end) q4amount tablename group seller
Comments
Post a Comment