1. oracle,使用3層巢狀
[quote]
select
* from
(select
b.*, rownum as rn
from
(select
*from
ms_user
where
comp_cd = '1'
order by
login_user_id
)b ---1.先查出符合條件資料
where
rownum <= 20 ---2.找出20行之前資料
)cwhere
c.rn >=10 ---3.找出10行之後資料
[/quote]
sql執行時會被優化,第二層的條件會被整合在最內層裡,所以實際上子查詢抽出的只是符合條件的20行之前的資料,所以這個sql在查詢靠前的資料時,比較快,越向後越慢。
各種資料庫分頁的sql語句
1.oracle資料庫分頁 select from select a.rownum rc from 表名 where rownum endrow a where a.rc startrow 2.db2資料庫分頁 select from select rownumber over as rc,a.fr...
各種資料庫分頁查詢sql語句
1.oracle資料庫分頁 select from select a.rownum rc from 表名 where rownum endrow a where a.rc startrow 2.db2資料庫分頁 select from select rownumber over as rc,a.fr...
各種資料庫分頁查詢sql語句大全
在顯示記錄條目時往往要用到分頁,一種常用的辦法是利用各種資料庫自帶的定位介面對原始查詢語句進行改寫,從而只取出特定範圍的某些記錄。不同的資料庫,查詢定位介面是不一樣的,下面做一彙總 資料庫分頁查詢語句 說明mysql query sqllimit 使用limit關鍵字,第乙個 是起始行號,第二個 是...