--取出工資最高的前5位 select empno,ename,sal,rownum from emp; select * from (select * from emp order by sal desc) where rownum<=5; select * from (select ename,sal,row_number() over(order by sal desc) as num from emp) where num<=5; select * from (select ename,sal,row_number() over(order by sal desc) from emp) where rownum<=5 --工資的前3名 select * from emp where sal >=any(select * from (select sal from emp order by sal desc) where rownum<=3); select * from(select * from emp order by sal desc) where rownum <4; select * from (select ename,sal,empno,deptno ,row_number() over (order by sal desc) from emp) where rownum<4; select * from (select ename,sal,empno,deptno ,row_number() over (order by sal desc) as num from emp) where num<4 --按照工資排序,取出第6名到第10名 --使用偽列獲得 select * from (select ename,sal,rownum r from (select * from emp order by sal desc) where rownum<=10) where r>5; --使用排名函數獲得 select * from (select ename,sal,row_number() over(order by sal desc) as num from emp) where num>5 and num<=10; ------- 按工資從高到低獲得工資排名第四的員工 select * from (select ename,sal,row_number() over(order by sal desc) as num from emp) where num=4; select * from (select ename,sal,rownum r from (select * from emp order by sal desc) where rownum<=4) where r=4;