当前位置: 代码迷 >> Oracle开发 >> where rownum <= 10条件的疑问解决思路
  详细解决方案

where rownum <= 10条件的疑问解决思路

热度:196   发布时间:2016-04-24 07:08:33.0
where rownum <= 10条件的疑问

select rownum,row_.*, rownum jres_db_rownum_
  from (select sa.ADJUST_ID,
              sa.STAFF_CODE,
              -- sa.SERIAL_NO,
              sa.CURR_DT,
              -- sa.DEAL_TM,
               sa.SALARY_SUBJECT,
               sa.OCCUR_BALANCE,
               sa.BRANCH_NO,
               sa.TEAM_NO,
               
               sa.OP_ACCOUNT,
               sa.REMARK,
               sa.audit_status
          from sly_adjustfarerecord sa
         where 1 = 1           
         order by audit_status, curr_dt desc, branch_no) row_

如上语句的结果如下:


疑问:为什么加条件后的结果不是1上面图中的前面10条呢,然后2图中得出的结果是按照什么逻辑得出的

------解决方案--------------------
select * from (select rownum rr,row_.*, rownum jres_db_rownum_   from (select sa.ADJUST_ID,               sa.STAFF_CODE,               -- sa.SERIAL_NO,               sa.CURR_DT,               -- sa.DEAL_TM,                sa.SALARY_SUBJECT,                sa.OCCUR_BALANCE,                sa.BRANCH_NO,                sa.TEAM_NO,                                 sa.OP_ACCOUNT,                sa.REMARK,                sa.audit_status           from sly_adjustfarerecord sa          where 1 = 1                     order by audit_status, curr_dt desc, branch_no) row_ ) bb where  bb.rr<11