oracle rownum对排序的影响
select *
from (select c.*, rownum rn from content c)
where rn >= 1
and rn <= 5
2. 但是如果, 加上order by addtime 排序则数据显示不正确
select *
from (select c.*, rownum rn from content c order by addtime)
where rn >= 1
and rn <= 5
解决方法,再加一层查询,则可以解决,
select *
from (select rownum rn, t.*
from (select title, addtime from content order by addtime desc) t)
where rn >= 1
and rn <= 5
如果要考虑到效率的问题,上面的还可以优化成(主要两者区别)
select *
from (select rownum rn, t.*
from (select title, addtime from content order by addtime desc) t
where rownum <= 10)
where rn >= 3
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。