SQL2005 ROW_NUMER는 페이지를 나누는 두 가지 일반적인 방식을 실현한다

690 단어
 
  
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]

좋은 웹페이지 즐겨찾기