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 的记录

猜你喜欢

转载自qll3609120.iteye.com/blog/2066227