序号 数量 日期
1 1 20131001
2 1 20131007
3 8 20131008
4 9 20131009
5 5 20131010
使用SQL语句查询出这样的结果:
1 1 20131001
2 2 20131007
3 9 20131008
4 17 20131009
5 22 20131010
也就是数量这一列为当天数量加上前一天的数量,谢谢
假设存储这些数据的表名为cal_amount,sunmber表示序号,amount表示数量,sdate表示日期,以下语句为一点拙见,望抛砖引玉。。。
with cal_amount_temp as
(select c.sunmber + 1 as sunmber, c.amount, c.sdate as sdate
from cal_amount c)
select a.sunmber, a.amount + nvl(b.amount, 0) as amount, a.sdate
from cal_amount a
left join cal_amount_temp b
on a.sunmber = b.sunmber
order by a.sunmber
但是,如果说“数量这一列为当天数量加上前一天的数量”,那么楼主结果中的最后一行为什么是22,而不是14?