Oracle 跪求时间倒序获取第二条记录
时间:2011-12-01
来源:互联网
数据如下:
REEMPLOYEEID SCANTIME
100000000088 2011-12-01 10:27:14
100000000088 2011-12-01 10:32:00
100000000088 2011-12-01 10:32:06
100000000104 2011-12-01 10:35:54
100000000088 2011-12-01 10:55:44
100000000106 2011-12-01 10:56:33
求结果:
REEMPLOYEEID SCANTIME
100000000088 2011-12-01 10:55:44
REEMPLOYEEID SCANTIME
100000000088 2011-12-01 10:27:14
100000000088 2011-12-01 10:32:00
100000000088 2011-12-01 10:32:06
100000000104 2011-12-01 10:35:54
100000000088 2011-12-01 10:55:44
100000000106 2011-12-01 10:56:33
求结果:
REEMPLOYEEID SCANTIME
100000000088 2011-12-01 10:55:44
作者: lovezx1028 发布时间: 2011-12-01
SQL code
select sub.reemployeeid, sub.scantime from (with a as( select '100000000088' as reemployeeid, '2011-12-01 10:27:14' as scantime from dual union all select '100000000088','2011-12-01 10:32:00' from dual union all select '100000000088','2011-12-01 10:32:06' from dual union all select '100000000104','2011-12-01 10:35:54' from dual union all select '100000000088','2011-12-01 10:55:44' from dual union all select '100000000106','2011-12-01 10:56:33' from dual ) select reemployeeid, scantime, row_number() over (order by scantime desc) as ss from a) sub where sub.ss = 2
作者: yixilan 发布时间: 2011-12-01
提供你一个方法供参考
select * from (select * from ss ORDER BY CANTIME desc )
where rownum<=2
minus
select * from (select * from ss ORDER BY CANTIME desc )
where rownum<=1
select * from (select * from ss ORDER BY CANTIME desc )
where rownum<=2
minus
select * from (select * from ss ORDER BY CANTIME desc )
where rownum<=1
作者: money729 发布时间: 2011-12-01
SQL code
select reemployeeid, scantime from (select t.reemployeeid, t.scantime, RANK() OVER(order by scantime) as RowNumber from tab t) b where b.RowNumber + 1 = (select max(RowNumber) from (select t.reemployeeid, t.scantime, RANK() OVER(order by scantime) as RowNumber from tab t))
作者: programmerxiaocai 发布时间: 2011-12-01
引用 2 楼 money729 的回复:
提供你一个方法供参考
select * from (select * from ss ORDER BY CANTIME desc )
where rownum<=2
minus
select * from (select * from ss ORDER BY CANTIME desc )
where rownum<=1
提供你一个方法供参考
select * from (select * from ss ORDER BY CANTIME desc )
where rownum<=2
minus
select * from (select * from ss ORDER BY CANTIME desc )
where rownum<=1

作者: rfb0204421 发布时间: 2011-12-01
测试数据
SQL code
结果
SQL code
CREATE TABLE T26 ( ReemployeeID VARCHAR2(20), ScanTime DATE ); INSERT INTO T26 VALUES('100000000088', to_date('2011-12-01 10:27:14', 'YYYY-MM-DD HH24:MI:SS')); INSERT INTO T26 VALUES('100000000088', to_date('2011-12-01 10:32:00', 'YYYY-MM-DD HH24:MI:SS')); INSERT INTO T26 VALUES('100000000088', to_date('2011-12-01 10:35:54', 'YYYY-MM-DD HH24:MI:SS')); INSERT INTO T26 VALUES('100000000104', to_date('2011-12-01 10:32:06', 'YYYY-MM-DD HH24:MI:SS')); INSERT INTO T26 VALUES('100000000088', to_date('2011-12-01 10:55:44', 'YYYY-MM-DD HH24:MI:SS')); INSERT INTO T26 VALUES('100000000106', to_date('2011-12-01 10:56:33', 'YYYY-MM-DD HH24:MI:SS'));
结果

作者: LuiseRADL 发布时间: 2011-12-01
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28