sqlserver中分页的方式
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;
生活赋予我们一种巨大的和无限高贵的礼品,这就是青春:充满着力量,充满着期待志愿,充满着求知和斗争的志向,充满着希望信心和青春。