select a.time-b.time from
(select id,time from test where id=(select max(id) from test) ) a,
(select id,time from test where id=(select max(id)-1 from test)) b;
(select id,time from test where id=(select max(id) from test) ) a,
(select id,time from test where id=(select max(id)-1 from test)) b;
解决方案 »
- oracle中报缺失表达式的错误,写错了吗,希望各位指点下
- oracle10g备份和回复
- 在sql server 中如何向异地的oracle 数据库中插入记录
- 请问:oracle中的表、数据文件和段、区,之间,有什么联系呢?
- oracle客户端安装网络配置怎么都配都不行啊
- group 的很奇怪的问题,怀疑是BUG
- 高分求助存储过程问题!!!
- 如何把表A的字段A_ID替换成001,002,003,004,005,....有序的自动增加1的数据?(初学),
- 怎么会:单行子查询返回多于一行呢?明明是唯一标志的
- 在线等待(狂加分)请问一个登陆错误的的原因!!!
- 求 oracle error code 文档?赠分
- 请教高手:左右联接(+)能否在多个表(2个以上)之间使用?
SELECT t.id,t.time,
lead(t.time,1,NULL) over (ORDER BY t.time) Next_time
FROM table t
-- -----------
1 2003-1-1
1 2003-2-6
1 2003-1-5SQL> select time-lead(time,1,null) over(order by time) from aaa;TIME-LEAD(TIME,1,NULL)OVER(ORD
------------------------------
-4
-32上述就不能以order by time,这样吧:
SQL> select time-lead(time,1,null) over(order by rownum) from aaa;TIME-LEAD(TIME,1,NULL)OVER(ORD
------------------------------
-36
32
如果问题是这样的
tablename:test
字段:id,id2,time
记录内容:
id id2 time
1 11 2003-2-1
2 22 2003-2-3
3 22 2003-2-12
4 11 2003-3-1
5 22 2003-3-12
要求求出id2=11最后2条纪录的时间差
select a.time -b.time from (
select rownum,id2,time form
(select id,time from test where id2=11 order by time desc)
where rownum<3 ) a, select rownum,time form
(select id,id2 time from test where id2=11 order by time desc)
where rownum<3 ) b
where a.rownum=2 and b.rownum=1 and a.id2=b.id2
tablename:test
字段:id,id2,time
记录内容:
id id2 time
1 11 2003-2-1
2 22 2003-2-3
3 22 2003-2-12
4 11 2003-3-1
5 22 2003-3-12
要求求出id2=11最后2条纪录的时间差
也就是求第4条纪录和第1条纪录的时间差
我不懂分析函数,能不能写的具体点!
谢谢
如果问题是这样的
tablename:test
字段:id,id2,time
记录内容:
id id2 time
1 11 2003-2-1
2 22 2003-2-3
3 22 2003-2-12
4 11 2003-3-1
5 22 2003-3-12
6 11 2003-4-1
要求求出id2=22最后2条纪录的时间差
也就是求第5条纪录和第3条纪录的时间差
我只想得到一条结果
我不懂分析函数,能不能写的具体点!
谢谢
select time-lead(time,1,null) over(partition by id2 order by rownum) from test
where id2='11';
一又有机会给你补上