-- ROW_NUMBER() Over() 分页,计算公式 ((@pageIndex - 1) * @pageSize) + 1 And ( @pageIndex * @pageSize )
DECLARE @pageSize INT
DECLARE @pageIndex INT
--第4页,每页显示5条数据
SET @pageIndex = 2
SET @pageSize = 5
select * from
(
select Student.Sname as 学生,Course.Cname as 分数,SC.score as 科目 ,Teacher.Tname as 授课老师,ROW_NUMBER()
over (order by Student.SID) as RowNumber from Student
join SC on Student.SId = SC.SId
join Course on SC.SId = Course.CId
join Teacher on Course.TId = Teacher.TId
where Student.Sname like N'%%'
) as res WHERE RowNumber BETWEEN ( ( @pageIndex - 1 ) * @pageSize ) + 1 AND ( @pageIndex * @pageSize )