日期:2014-05-16 浏览次数:20839 次
select * from (select t.*, row_number() over(order by empno) as r1, -- 顺序 row_number() over(order by empno desc) as r2 -- 倒叙 from emp t) where r1 <= 5 or r2 <=5 order by empno;
------解决方案--------------------
rownum可以实现,只不过要用子查询来实现,因为rownum是不可以直接用<n(n>1) 不过如果在外面用一层子查询就可以了阿 select * from (select id,name, rownum rt from table order by id) where rt <=5 union all select * from (select id,name, rownum rt from table order by id desc) where rt <=5 --ps:如果有不足10条数据的情况,可以使用union 去掉重复数据
------解决方案--------------------
原数据是:1-20 select rn from ( select rownum rn from dual connect by rownum<21 ) where rn<6 or rn>15 --结果显示: 1 1 2 2 3 3 4 4 5 5 6 16 7 17 8 18 9 19 10 20