SQL2005 ROW_NUMER实现分页的两种常用方式
程序员文章站
2022-04-23 20:17:57
复制代码 代码如下:declare @pagenumber int declare @pagesize int set @pagenumber=2 set @pagesiz...
复制代码 代码如下:
declare @pagenumber int
declare @pagesize int
set @pagenumber=2
set @pagesize=20
--利用between
select *
from
(
select
row_number() over (order by source_ip,id) as row_num,
* from tb) as page_table
where row_num between (@pagenumber - 1) * @pagesize + 1 and @pagenumber * @pagesize
--利用top方式
select top 20 *
from
(
select
row_number() over (order by source_ip,id) as row_num,
* from tb
) as page_table
where row_num > (@pagenumber - 1) * @pagesize
order by row_num
[/code]