使用开窗函数over()
select *
from
(
select *,ROW_NUMBER() over(order by userID)as num
from usserMessage
) as T
where T.num between 4 and 6
定义变量法
declare @i int
set @i=4
select top 2 *
from student
where studentID not in
(select top ((@i-1)*2) studentID
from student
)