SQL Server 数据分页查询

2018-10-29  本文已影响9人  抄无止境

数据库表 image

方法一

select top 5 * 
  from [StuDB].[dbo].[ScoreInfo] 
  where [SID] not in 
    (select top 10 [SID] 
    from [StuDB].[dbo].[ScoreInfo] 
    order by [SID])
  order by [SID]

方法二

  select top 5 * 
  from [StuDB].[dbo].[ScoreInfo] 
  where [SID]> 
    (select MAX(t.[SID]) from (select top 10 [SID] from [StuDB].[dbo].[ScoreInfo] order by [SID]) t )
  order by [SID]

方法三

  select * 
  from (select *,ROW_NUMBER() over(order by [SID]) ROW_ID from [StuDB].[dbo].[ScoreInfo]) t
  where t.[SID] between (5*(3-1)+1) and 5*3

方法四

  select * 
  from [StuDB].[dbo].[ScoreInfo]
  order by [SID] 
  offset 5*2 rows fetch next 5 rows only

文章来源
https://www.cnblogs.com/Brambling/p/6031782.html

上一篇 下一篇

猜你喜欢

热点阅读