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

编程学习 2021-07-05 16:33www.dzhlxh.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


--利用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]

Copyright © 2016-2025 www.dzhlxh.cn 金源码 版权所有 Power by

网站模板下载|网络推广|微博营销|seo优化|视频营销|网络营销|微信营销|网站建设|织梦模板|小程序模板