首页 > 数据库 >SqlServer 几种分页方式

SqlServer 几种分页方式

时间:2023-01-12 11:37:43浏览次数:49  
标签:10 分页 top SqlServer 几种 Student order Id select

  1. top 方式
select top 5 * from  Student  where Id >(select max(Id) from (select Top 10 Id from Student order by Id ) as b) order by Id 
--或使用not in
select top 5 * from  Student  where Id not in (select Top 10 Id from Student order by Id ) order by Id 

通用语句,适用mysql 等数据库,查询靠前数据快

  1. ROW_NUMBER 方式
select * from (select * ,Row_Number() over (Order by Id) as RowNumber from Student ) as b where RowNumber BETWEEN 11 AND 15;

sqlserver2008R2 以上使用,查询靠后数据快

  1. offset fetch next 方式
select * from Student order by Id offset 10 row fetch next 5 row only;

sqlserver2012 以上使用,速度最快

注:其他游标等方式暂不考虑

标签:10,分页,top,SqlServer,几种,Student,order,Id,select
From: https://www.cnblogs.com/lyang129/p/17045961.html

相关文章