i have table stores date , price of purchases.
for example
date | price --------------------- 2014-1-12 | 6.50 2014-2-34 | 10.99 2015-1-01 | 3.22 2015-2-14 | 4.12 and on.
what want achieve: query outputs sum of purchases grouped per month of year.
the important thing is, though, need have different years in columns able make graph separate line each year. output need this:
month | 2014 | 2015 jan | 123.23 | 99.1 feb | 457.00 | 122.00 mar | 299.99 | 789.12 ... | nov | 333.33 | 10.99 dec | 100.00 | 20.10 is possible? searched quite long time things "year on year" query etc. not find anything.
any appreciated!
just use conditional aggregation:
select monthname(date) mon, sum(case when year(date) = 2014 price else 0 end) price_2014, sum(case when year(date) = 2015 price else 0 end) price_2015 table t group monthname(date) order max(month(date));
Comments
Post a Comment