Sort by salary in descending order. If the salary is the same, sort by employment date. 6 ~ 10 records, required
Example: sort by salary in descending order. If the salary is the same, sort by employment date. Get 6 ~ 10 records
1. Obtain the list of employees in descending order of wages and employment dates in ascending order.
Select * from emp order by sal desc, hiredate asc;
2. Get the rownun variable
Select t. *, rownum rn from (select * from emp order by sal desc, hiredate asc) t;
3 get 6 ~ 10 records
Select a. * from (select t. *, rownum rn from (select * from emp order by sal desc, hiredate asc) t) a where a. rn between 6 and 10;
PS: in practice, it is best not to use * instead of all columns to directly display the required columns without displaying the sequence of rownum.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.