首页 >数据库 >mysql教程 >SQL2005 ROW_NUMER实现分页的两种常用方式

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

WBOY
WBOY原创
2016-06-07 18:04:381219浏览

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]

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn