这种方法是最优方法,因为该方法进行排序后取值,所以能够保证两次取值都会取出相同的值。
最里面的那层select是提取满足要求的所有数据,然后第二层select用于选取前n条数据,最外面的select语句用于选取第m条之后的数据。
#Oracle从目标表中查询第m条到第n条的相应字段
select * from
(select tt.*, rownum, rn from
(select <想要查询的目标字段>
from 目标表
where 筛选条件) tt
where rownum < n)
where rn > m
该方法的思想是找出前n条数据和前m条数据,然后对两个集合求取差集即可。因为SQL语句的执行顺序问题,order by总是最后执行,所以下方的SQL可以执行,但在任意一个select语句中添加order by会报错。
所以这种方法因为没有按照一定的标准排序后取值,所以有概率两次取值有稍微不同。
select <目标字段> from A where rownum < n
minus
select <目标字段> from A where rownum < m
select * from
(select 目标字段 from 目标表 where rownum < n) b
where b.id not in (select id from 目标表 where rownum < m)
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有