mysql 累计求和

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

posted @ 2017-11-22 10:18  霂雨  阅读(3186)  评论(0编辑  收藏  举报