Oracle中rownum与order by的执行顺序

执行顺序
Oracle会先设置行的rownum,再进行order by
执行顺序:rownum > order by

正确的写法应该是先order by,先包一层查询,再赋rownum值

select *
from (select rownum rno, t1.*
from (select *
from (select sysdate + level level_ from dual connect by level <= 10) t
order by level_ desc) t1) t2
where t2.rno <= 3

 

posted @ 2021-03-10 11:41  南国之恋  阅读(1423)  评论(0编辑  收藏  举报