--利用开窗函数,并将其当作结果集 查询其31到第40条select*from(select*,ROW_NUMBER()over(orderby id) 排序 from Product) A
where A.排序 between31and40;--先查询前三十条,在查询十条 并且id不再这三十条中selecttop(10)*from Product
where id notin(selecttop(30) Id from Product);--必须有四十条数据,否则会取三十条之前的selecttop(10)*from(selecttop(40) Id from Product orderby Id)as a orderby a.Id desc;--先查询前三十条数据 并在这些数据中找到最大的id,最后查询10条id比这个最大id大的数据selecttop(10)*from Product where Id >(selectmax(Id)from Product where Id in(selecttop(30) Id from Product));--EXCEPT 从左侧输入查询返回非由右侧输入查询输出的非重复行。--表连接的差集运算(EXCEPT)selecttop(40)*from Product exceptselecttop(30)*from Product;selecttop10*from A where id >(selectmax(id)from(selecttop30 id from A )as A);
sql求31到第40条数据(id不连续)--利用开窗函数,并将其当作结果集 查询其31到第40条select* from (select *,ROW_NUMBER() over(order by id) 排序 from Product) Awhere A.排序 between 31 and 40;--先查询前三十条,在查询十条 并且id不再这三十条中select top(10) * from Product where id not in(select top(30) Id from Prod