方法一、
alter procedure PagedQuery
(
@size int, 页大小
@pageIndex int 页索引
)
as
select top (@size) * from class where classid not in (select top(@size*@pageIndex) classid from class order by classid)
go
exec PagedQuery 3,0
方法二、
create procedure PagedQuery2
(
@size int,
@pageIndex int
)
as
select a.* from (select *,ROW_NUMBER() over(order by classid asc) as RowNo from class) as a
where RowNo between (@size* @pageIndex+1) and (@size* (@pageIndex+1))
go
exec PagedQuery2 4,0
(注:分组分页查询,row_number() OVER (PARTITION BY COL1 ORDER BY COL2) 表示根据COL1分组,在分组内部根据 COL2排序,而此函数计算的值就表示每组内部排序后的顺序编号(组内连续的唯一的))