SQL2000与SQL2005下高效分页语句
2010-06-19 22:04 Tacker 阅读(1539) 评论(3) 编辑 收藏 举报SQL SERVER 2000:
1 select top 30 * from users
2 where userid<(select min(userid) from (select top 900000 userid from users order by userid desc) as tmp)
3 order by userid desc
2 where userid<(select min(userid) from (select top 900000 userid from users order by userid desc) as tmp)
3 order by userid desc
SQL SERVER 2005:
1 select * from (
2 select row_number() over(order by userid desc) RowNumber,*
3 from (select top 900030 userid from users ) as t
4 ) as tt
5 where RowNumber>900000
2 select row_number() over(order by userid desc) RowNumber,*
3 from (select top 900030 userid from users ) as t
4 ) as tt
5 where RowNumber>900000
userid为索引字段,users为表名