1,数据表:
2,效果图:
拿走不谢:
现成的没有,只有参考:
https://www.cnblogs.com/lcword/p/5719298.html
select a.userid, a.month, a.salary, sum(case when a.month<=b.month then b.salary else 0 end) as balancefrom 表 aleft join 表 b on a.userid=b.useridgroup by a.userid, a.month, a.salaryorder by 1,2
select userid,month,salary,
sum(salary) over(partition by userid order by month asc) as balance
from table order by userid asc,month asc