`
qll3609120
  • 浏览: 55389 次
社区版块
存档分类
最新评论

sql server 分页查询的3种方法

 
阅读更多

一: not in

 例:select top 10 * from 表 where id not in (select top 10 id form 表)

z这是嵌套查询 子查询查询数据表的前10条记录,外面的查询是查询不在这些记录中的前10条 也就是数据库中的10-20条

二:max

例:select top 10 * from 表 where id>(select max(id) from(select top 10 id from 表 ) tt(别名))

这个嵌套查询先查出数据库表中前10条数据的最大Id(max(id)),然后再查出id>max(id)的前10条数据

 

三:row

例:select *from(select row_number() over(order by tempNumber)tempRowNumber,from (select top 100 tempNumber=0,*from 表)t)tt
 where tempRowNumber>50)

查询100条数据中tempRowNumber>50 的记录

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics