欢迎来到福编程网,本站提供各种互联网专业知识!
您的位置:网站首页 > 数据库 > MsSql2005

SQL2005 高效分页sql语句

发布时间:2010-05-07 作者: 来源:转载
SQL2005高效分页sql语句,需要的朋友可以参考下。
1、
复制代码 代码如下:
select top 10 * from
( select top (@Page * 10) ROW_NUMBER() OVER (order by id) as RowNum, id, username
from Guest where username = 'user'
) as T
where RowNum > ((@Page - 1) * 10)

2、
复制代码 代码如下:
select * from
( select ROW_NUMBER() OVER(order by id) as RowNum,id,username
from Guest where username = 'user'
) as T
where RowNum between 31 and 60

3、
复制代码 代码如下:
with T as
(select ROW_NUMBER() OVER(order by id) as RowNum,,id,username
from Guest where username = 'user'
)
select * from T
where RowNum between 31 and 60

相关推荐