SELECT * FROM (VALUES('Jan',100),
('Jan',150),('Jan',50),('Feb',70),('Feb',80)
) temp_table(MONTH_NAME,BALANCE)
), b as (
select *, row_number() over(partition by MONTH_NAME) as rn
from a
)
select month_name, balance, sum(balance) over(partition by month_name order by rn) as running_balance
from b
with a AS ( SELECT * FROM (VALUES('Jan',100), ('Jan',150),('Jan',50),('Jan',150),('Feb',70),('Feb',80) ) temp_table(MONTH_NAME,BALANCE) ), b as ( select *, row_number() over(partition by MONTH_NAME) as rn from a ) select rn, month_name, balance, sum(balance) over(partition by month_name order by rn) as running_balance from b
0 Response to "sum balance per month postgres"
Posting Komentar