select id,createdate,finvoutype from nc_ext_fa_ls_pz_hzdoc doc
where doc.company = '3000004' and doc.finvoutype = 'YUFZXD'
and doc.gxmlflag = '20220107'
and rownum <=10 order by doc.createdate
第一种方法:id:6321 没取值出来;
select id from (
select id from nc_ext_fa_ls_pz_hzdoc doc
where doc.company = '3000004' and doc.finvoutype = 'YUFZXD'
and doc.gxmlflag = '20220107'
order by doc.createdate) where rownum <=10
第二种方法: id:6321 能取值出来;
执行顺序
Oracle会先设置行的rownum,再进行order by
执行顺序:rownum > order by
正确的写法应该是:先order by,先包一层查询,再赋rownum值