1.使用top進行:sql
1.select top 頁大小 * from 表名where id not in(select top 頁大小*(查詢第幾頁-1) id from 表名 order by id)order by id --全盤掃描,不太好spa
2.SELECT
TOP
10 *
FROM
[TCCLine].[dbo].[CLine_CommonImage]
code
WHERE
(
ID >
(
SELECT
MAX
(id)
FROM
(
SELECT
TOP
40 id
FROM
[TCCLine].[dbo].[CLine_CommonImage]
ORDER
BY
id)
AS
T)
)
ORDER
BY
ID
/* * firstIndex:起始索引 * pageSize:每頁顯示的數量 * orderColumn:排序的字段名
* SQL:能夠是簡單的單表查詢語句,也能夠是複雜的多表聯合查詢語句、
*/
select [top pageSize] o.* from (select row_number() over(order by orderColumn) as rownumber,* from(SQL) as o) where rownumber>firstIndex;--總共15條記錄,分3頁,每頁5條記錄,現查詢第3頁的內容如:select * from ( select row_number() over(order by EmpID) as rownumber,* from book.dbo.Empmgr) as tt where rownumber > 10;