----------------------------------------------
| id | product| price| chain| location| date |
----------------------------------------------
我需要把它显示为:
2018年9月(每月)
| sum for the month | sum for the year so far
----------------------------------------------------------------
location | 100 | 200
product1 | 1 | 2
product2 | 99 | 198
-----------------------------------------------------------------
Total | 100 | 200
=================================================================
enter code here
enter code here
select date_trunc('month', date) as yyyymm, sum(price),
sum(sum(price)) over (partition by extract(year from date) order by min(date)) as ytd
from location
group by grouping sets ( (yyyymm), () );