首页 > 数据库 > SQL Server > 正文

SQL2005 高效分页sql语句

2024-08-31 01:01:14
字体:
来源:转载
供稿:网友
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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表