資料庫的分頁演算法

2021-04-25 20:16:09 字數 867 閱讀 5057

各個資料庫的分頁演算法 

1.sql server 是用先逆序再正序的方法

select top 3 * from (select top 9 * from mvc_book order by bid) as s order by s.bid desc [第6,5,4條]

select * from (select top 3 * from (select top 6 * from mvc_book order by bid) as s order by s.bid desc) as s1 order by s1.bid [第4,5,6條]

select top 6 * from mvc_book where (bid not in (select top 2 bid from mvc_book))[第3,4,5,6,7,8條]

2.oracle 用minus和rownum來實現 (minus 減去 union 聯合 intersect 返回相同的記錄集)

select * from t_service_vnet_send where rownum <= 15 minus select * from t_service_vnet_send where rownum <= 10;

或select * from (select rownum no,id,age,name from loaddata where rownum <= 3 ) where no >= 2;

3.db2

select * from (select row_number() over() as a, org.* from org) as temp where a>=n1 and a<=n2

4.mysql

select * from tablename limit m,n;

資料庫分頁

mysql 分頁採用limt 關鍵字select from t order limit 5,10 返回第6 15 行資料 select from t order limit 5 返回前5 行 select from t order limit 0,5 返回前5 行 mssql 2000 分頁採用to...

資料庫分頁

oracle分頁 方法1 根據rowid來分 select from uop crm1.tf f user where rowid in select rid from select rownum r,rid from select rowid rid from uop crm1.tf f user...

資料庫分頁

一 mysql 資料庫分頁查詢 mysql資料庫實現分頁比較簡單,提供了limit函式。一般只需要直接寫到sql語句後面就行了。limit子句可以用來限制由select語句返回過來的資料數量,它有乙個或兩個引數,如果給出兩個引數,第乙個引數指定返回的第一行在所有資料中的位置,從0開始 注意不是1 第...