gpt4 book ai didi

mysql - 按两列更新累积和

转载 作者:行者123 更新时间:2023-11-29 10:36:24 24 4
gpt4 key购买 nike

大家好,我需要帮助!

我有一个像这样的表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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com