欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

SQL2005 高效分页sql语句

程序员文章站 2022-05-23 18:18:00
1、 复制代码 代码如下: select top 10 * from ( select top (@page * 10) row_number() over (order...
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