SQL分页简单语句

DECLARE @pageSize int
DECLARE @pageIndex int
set @pageSize= 30
set @pageIndex=4

SELECT TOP (@pageSize) *
FROM Student
WHERE snumber NOT IN
(SELECT TOP (@pageSize * (@pageIndex-1)) snumber FROM Student)

DECLARE @pageSize int
DECLARE @pageIndex int
set @pageSize= 10
set @pageIndex=1

SELECT *
FROM ( SELECT TOP ( @pageSize * @pageIndex )
ROW_NUMBER() OVER ( ORDER BY dbo.student.snumber ) AS rownum ,
*
FROM dbo.Student
) AS temp
WHERE temp.rownum > ( @pageSize * ( @pageIndex – 1 ) )

ORDER BY temp.SNumber

发表评论

电子邮件地址不会被公开。 必填项已用*标注