sql server 分页
/* top 分页
top 3* 一页3条数据 取第一页的数据
not in ....截掉前4页数据
//去第5页的数据
select top 3 * from dbo.student WHERE ID NOT IN(SELECT TOP(3*4) ID FROM dbo.student);
*/
/*
ROW_NUMBER()over() 分页
新增一列number用来记录行的顺序 order by 作为排序标准 =〉 新表tb1
从tb1里获取想取的分页
--取第一页的数据
select * from (select * ,ROW_NUMBER()over(order by ID asc) as number from dbo.student ) as tb1
where number between 1 and 3;
*/
/*
create by wu_YP on 2019-8-19
description:
学生表按ID排序分页
EXEC PagePagination 10,1
*/
IF EXISTS(SELECT 1 FROM sysobjects WHERE xtype='p' AND name='PagePagination')
BEGIN
drop proc PagePagination
END
go
CREATE PROC PagePagination
(
@PageSize INT,--分页大小
@PageIndex INT --分页索引
)
AS
SELECT TOP (@PageSize) *
FROM
(
SELECT ROW_NUMBER() OVER (ORDER BY id) AS RowNumber,* FROM dbo.student
) as IndexTable
WHERE RowNumber > @PageSize*(@PageIndex-1)