sql server 2005中row_number实现分页的例子
本文导语: 供大家学习参考。 代码示例: ---row_number分页实例 ---by http://www. 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_test_news) as ...
供大家学习参考。
---row_number分页实例
---by http://www.
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_test_news) 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_test_news
) as page_table
where row_num > (@PageNumber - 1) * @PageSize
order by row_num