SQL2005 ROW_NUMER实现分页的两种常用方式

网络编程 2021-07-05 16:33www.168986.cn编程入门
SQL2005利用ROW_NUMER实现分页的两种常用方式

代码如下:

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


--利用方式

select 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]

Copyright © 2016-2025 www.168986.cn 狼蚁网络 版权所有 Power by