SQL> select * from test
2 /ID NO QUANTITY NEWDATE
---------- ---------- ---------- ----------
1 B101 8 01-7月 -05
2 B003 89 01-7月 -05
3 B102 76 03-7月 -05
4 B101 9 04-7月 -05
5 B101 32 06-7月 -05
6 B102 11 05-7月 -05
7 B102 70 08-7月 -05
8 B101 202 09-7月 -05已选择8行。SQL> select t.*,quantity - quantity1 from
2 (select NO,quantity,newdate,
3 lead(NO) over(partition by NO order by newdate desc) NO1,
4 lead(quantity) over(partition by NO order by newdate desc) quantity1
5 from test) t
6 where NO1 is not null
7 /NO QUANTITY NEWDATE NO1 QUANTITY1 QUANTITY-QUANTITY1
---------- ---------- ---------- ---------- ---------- ------------------
B101 202 09-7月 -05 B101 32 170
B101 32 06-7月 -05 B101 9 23
B101 9 04-7月 -05 B101 8 1
B102 70 08-7月 -05 B102 11 59
B102 11 05-7月 -05 B102 76 -65
2 /ID NO QUANTITY NEWDATE
---------- ---------- ---------- ----------
1 B101 8 01-7月 -05
2 B003 89 01-7月 -05
3 B102 76 03-7月 -05
4 B101 9 04-7月 -05
5 B101 32 06-7月 -05
6 B102 11 05-7月 -05
7 B102 70 08-7月 -05
8 B101 202 09-7月 -05已选择8行。SQL> select t.*,quantity - quantity1 from
2 (select NO,quantity,newdate,
3 lead(NO) over(partition by NO order by newdate desc) NO1,
4 lead(quantity) over(partition by NO order by newdate desc) quantity1
5 from test) t
6 where NO1 is not null
7 /NO QUANTITY NEWDATE NO1 QUANTITY1 QUANTITY-QUANTITY1
---------- ---------- ---------- ---------- ---------- ------------------
B101 202 09-7月 -05 B101 32 170
B101 32 06-7月 -05 B101 9 23
B101 9 04-7月 -05 B101 8 1
B102 70 08-7月 -05 B102 11 59
B102 11 05-7月 -05 B102 76 -65
解决方案 »
- 求sql查询语句
- 紧急求助,在线等待!
- oracle求助,关于修改时间问题?急~~~~谢谢各大高手
- 请教一个数据集成平台实时数据的导入导出问题
- 请教,关于物化视图的刷新问题!
- like '%%' 和like '%' 的区别!
- 我在系统(win2000server)上强制关掉进程ORACLE,结果重新启动后数据库就不能打开了?有什么办法可以解决的呀?!谢啦
- 小问题,急~!!
- 请问oracle怎么样进入 enterprise manager
- 询问一个SQL语句
- 特急求助!请多个有经验大侠支援,不必全部回答,针对里面的其中一两个问题尽可能回答,分数不够的开多个相同帖给分
- Oracle计划任务问题:执行任务时的出错处理??在线等。。。。
A.quantity as quantity,
A.date as date,
A.No as No1,
B.quantity as quantity1,
B.date as date1
(A.quantity-B.quantity) as differ
from test A,
test B
where A.No = B.No
and B.date = (select max(date) from test where No=A.No and date < A.date)
order A.date dec