1. 程式人生 > >Oracle分頁查詢的提升階段

Oracle分頁查詢的提升階段

--Oracle分頁查詢
--簡單初級階段
SELECT * FROM (SELECT * FROM score s ORDER BY math DESC) WHERE ROWNUM = 1;

--中級階段,基本實現了結果,但仍有可優化的空間!
SELECT *
  FROM (SELECT so.*, ROWNUM rw
          FROM (SELECT * FROM score s ORDER BY math DESC) so) sa
 WHERE sa.rw >= 1
   AND sa.rw <= 4;

--究極形態...!效率最高!
SELECT *
  FROM (SELECT SO.*, ROWNUM RW
          FROM (SELECT * FROM SCORE S ORDER BY MATH DESC) SO
         WHERE ROWNUM <= 4) SA
 WHERE SA.RW >= 1;


想繼續深入,可參照大牛的這篇文章: