表 t
day qty
1 4
2 1
3 7
SELECT t1.day,
day qty
1 4
2 1
3 7
SELECT t1.day,
(SELECT SUM(t2.qty) FROM t AS t2
WHERE t2.day <= t1.day) as acqty -- 累计数量
FROM t AS t1
查询结果
day qty
1 4
2 5
3 12
FROM t AS t1
查询结果
day qty
1 4
2 5
3 12