page 当前页,pageSize 每页大小
1、
order by [字段] offset [preIndex] rows fetch next [rowNum] rows only
select * from ( select row_number() over(order by createTime desc) as id, * from test ) tmp order by id offset 10 rows fetch next 5 rows only;
总结:这种方式的起始值与结束值计算方式: offset (当前页数-1)*页大小+1 rows fetch next 页数 rows only
order by id offset (page-1)*pageSize rows fetch next pageSize rows only;
2. row_number() over()加序号,通过序号取分页
下面以取第 11 - 15 的数据为例
select * from ( select row_number() over(order by createTime desc) as id, * from test )tmp where id between 11 and 15
总结: 这种方式采用 RowId BETWEEN (当前页数-1)*页大小+1 and 页数*页大小 ,而且包含起始值与结束值
where id between (page-1)* pageSize+page* pageSize标签:rows,分页,pageSize,order,sql,id,select,page From: https://www.cnblogs.com/michellexiaoqi/p/18325596