Preview:
--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
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter