只取前N条数据是比较容易的,使用 select * from a where rownum<=100 order by b 可以在不使用任何索引的情况下,将速度提升到很高。但是rownum不支持>=,所以不能实现取一个范围。可以通过
select * from
(
select a.*,rownum r from a where rownum<=200 order by b
) where r<=N
来实现这个功能,但是随着N的增大,该表排序的时间会越来越长,当查询99990到第100000条记录时速度和全表排序差不多慢,请问各位有没有什么好的方法
=====================================================
select tt.* from
(
select rownum r,t.* from
(select * from A order by b) t
)tt
where tt.r>=100 and tt.r<=200
select * from
(
select a.*,rownum r from a where rownum<=200 order by b
) where r<=N
来实现这个功能,但是随着N的增大,该表排序的时间会越来越长,当查询99990到第100000条记录时速度和全表排序差不多慢,请问各位有没有什么好的方法
=====================================================
select tt.* from
(
select rownum r,t.* from
(select * from A order by b) t
)tt
where tt.r>=100 and tt.r<=200
本文探讨了在不使用索引情况下,如何通过SQL语句优化实现快速分页查询的方法。针对只支持小于等于(<=)而不支持大于等于(>=)的ROWNUM特性,介绍了一种通过嵌套查询来获取指定范围记录的技术方案。但该方法在查询接近尾部的记录时效率较低,因此寻求更优解决方案。

7004

被折叠的 条评论
为什么被折叠?



