表的倒数第二行数据

在oracle 的scott用户表下查询全表 使用rownum 代码如下: select * from emp where rownum >2为什么一条都数据都没有。

rownum只能用于<,如果要用>要么用rownumber()OVER,要么就实例化

rownumber()over:
select  * from (select t.*,row_number()over(order by empno desc) rn from emp t) a where a.rn=2;
实例化:
select * from (select t.*,rownum rk from (select * from emp order by empno desc) t)c where c.rk =2;
MsSql就倒数再倒数:
select top 1 * from (select top 2 * from emp t order by t.empno desc) t1 order by empno
 
原文地址:https://www.cnblogs.com/kenwong/p/3644581.html