服务器之家:专注于服务器技术及软件下载分享
分类导航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|数据库技术|

服务器之家 - 数据库 - Sql Server - SQL2005 高效分页sql语句

SQL2005 高效分页sql语句

2020-07-01 15:23sql数据库教程 Sql Server

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

延伸 · 阅读

精彩推荐