running-balance

Selecting sum and running balance for last 18 months with generate_series

会有一股神秘感。 提交于 2019-12-11 00:59:59
问题 I have this working query, but I need to add all months to my result, no matter if the items sold during that month: select * from ( select to_char(max(change_date), 'YYYY-MON')::varchar(8) as yyyymmm, max(change_date) as yearmonth, sum(vic.sold_qty / item_size.qty)::numeric(18,2) as sold_qty, -- sold monthly sum(sum(on_hand)) OVER (PARTITION BY vic.item_id order by year,month) as on_hand --running balance from (((view_item_change vic left join item on vic.item_id = item.item_id) left join