1.使用top进行:
1.select top 页大小 * from 表名where id not in(select top 页大小*(查询第几页-1) id from 表名 order by id)order by id --全盘扫描,不太好
2.SELECT
TOP
10 *
FROM
[TCCLine].[dbo].[CLine_CommonImage]
WHERE
(
ID >
(
SELECT
MAX
(id)
FROM
(
SELECT
TOP
40 id
FROM
[TCCLine].[dbo].[CLine_CommonImage]
ORDER
BY
id)
AS
T)
)
ORDER
BY
ID
2.row_number进行:
/* * 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;