用SQL语句查询累计值

表 t
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
posted @ 2009-06-26 14:19  NanKe Sir's Blog  阅读(1423)  评论(0编辑  收藏  举报