Mysql 按两列更新累积和
嗨,伙计们,我需要帮助 我有这样一个表sql:Mysql 按两列更新累积和,mysql,sql,Mysql,Sql,嗨,伙计们,我需要帮助 我有这样一个表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 我需要这样的结果: id | in | out 1 | 32 | 23 2 | 4 | 0 3 | 10 | 3 id | in | out| cumulative 1 | 3
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
我需要这样的结果:
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
选择id,
[in],
[外],,
(选择ABS(总和([out]-[in]))
从c2的临时工那里,我非常漂亮,非常感谢!