按工資降序排列,若工資相同,則按照僱傭日期尚需排列,擷取6~10 條記錄,尚需

來源:互聯網
上載者:User

按工資降序排列,若工資相同,則按照僱傭日期尚需排列,擷取6~10 條記錄,尚需

如題:按工資降序排列,若工資相同,則按照僱傭日期尚需排列,擷取6~10 條記錄


1 擷取工資降序,僱傭日期升序的員工列表


select * from emp order by sal desc, hiredate asc;


2 擷取rownun變數


select t.*, rownum rn  from (select * from emp order by sal desc, hiredate asc) t;



3 擷取6~10條記錄


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:實際應用中,最好不要用*代替所有列,直接將需要的列展示出來即可,同時不需要將rownum的序列展示出來。



著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.