oracle求表的倒数二行数据

转自http://www.itpub.net/thread-1854111-4-1.html

我选出的最佳方法有两个:
1.利用rownum
select * from (select t.*,rownum rn from (select * from emp e order by empno) t) where rn=2;
至于为何有多套了一层select,是因为emp这个表很特殊,数据是按empno排列的,以上这个写法可适用于所有无序表。

2.利用分析函数
select * from (select t.*,row_number() over(order by empno) rn from emp t)  where rn=2;

更详细结果见我的博客http://pandarabbit.blog.163.com/ ... 841442014344567267/

原文地址:https://www.cnblogs.com/xiaodangxiansheng/p/11457267.html