侧边栏壁纸
博主头像
Epoch

Java开发、Python爬虫、微服务、分布式、前端

  • 累计撰写 94 篇文章
  • 累计创建 111 个标签
  • 累计收到 8 条评论

目 录CONTENT

文章目录

不同数据库的分页实现原理

Epoch
2021-02-18 / 0 评论 / 0 点赞 / 345 阅读 / 210 字 / 正在检测是否收录...

不同数据库的分页实现原理

一、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
0

评论区