ID a
1 3
2 4
3 4
4 7
5 7
累计求和 为以下形式
ID a b
1 3 3
2 4 7
3 4 11
4 7 18
5 7 25
SELECT
ID,
a,
(SELECT SUM(a) FROM tb WHERE ID<=A.ID) AS b
FROM tb AS A
ID a
1 3
2 4
3 4
4 7
5 7
累计求和 为以下形式
ID a b
1 3 3
2 4 7
3 4 11
4 7 18
5 7 25
SELECT
ID,
a,
(SELECT SUM(a) FROM tb WHERE ID<=A.ID) AS b
FROM tb AS A
转载于:https://www.cnblogs.com/xiaoyii/p/7877937.html