不同数据库的分页实现原理
一、MySQL分页
select * from table limit 0,20
-- 第一个参数是起始的行号,第二个参数是从本行向后取多少条
二、Oracle分页
使用Oracle中的伪列来进行分页
下面一段意思是查询12-20条数据
select t3.* from(
select t2.* , rownum as row_num from(
select * from table order by id asc
) t2 where rownum <= 20
) t3
where t2.row_num>11
三、SQL Server 2000
旧版SQL Server分页(2000以前)
下面SQL意思是查询16-18三条数据
select top 3 * from table
where
id not in
(select top 15 id from table)
四、SQL Server 2012+
下面一段话的意思是
offset是偏移4行 从第五行开始
就是说获取 5、6、7、8、9五条数据
select * from table order by id
offset 4 rows fetch next 5 rows only
评论区