find cummulative sums in postgresql
Sun Apr 24 2022 02:50:14 GMT+0000 (Coordinated Universal Time)
Saved by
@Bambibo9799
--get the cash flow sum and cummulatie sales in the state new york in 2017
with extract_mm_filter_year_and_place as (
select extract(month from order_date) as mm,
state,sales
from orders_table as ot
where extract(year from order_date)=2017
and lower(state) = 'new york'
)
,summed_sales as(
select state,mm,round(sum(sales)) as cashflow
from extract_mm_filter_year_and_place
group by 1,2
)
select *,sum(cashflow)over(partition by state order by mm)
from summed_sales
content_copyCOPY
Comments