2015年1月13日 星期二

[SQL]取得第N筆的值


利用rownum外層再包一個select就可以做到取第N筆的值

SELECT *
FROM (select salary2.*, rownum rnum from
             (select * from salary ORDER BY salary_amount DESC) salary2
      where rownum <= 2 )
WHERE rnum >= 2;
http://www.techonthenet.com/oracle/questions/second_highest.php

沒有留言:

張貼留言