大家好,我需要帮助!
我有一个像这样的表sql:
id | in | out
1 | 32 | 23
2 | 4 | 0
3 | 10 | 3
我需要这样的结果:
id | in | out| cumulative
1 | 32 | 23 | 9
2 | 4 | 0 | 13
3 | 10 | 3 | 20
可以用sql来做吗?如何?谢谢
最佳答案
可以使用这样的子查询:
select id,
[in],
[out],
(SELECT ABS(SUM([out] - [in]))
from ##temp as c2 where id <= c1.id) as cumulative
from ##temp as c1
##temp 是您的表格
关于mysql - 按两列更新累积和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46345928/