Luo Hao

Oracle——递归查询写法

Rehoni / 2020-09-01


Oracle递归查询

 select * from
 (select t.EMPLOYEE_ID,
        EMPLOYEE_NAME,
        a.ORG_ID,
        b.ORG_NAME,
        t.SHORT_SPELL,
        t.FULL_SPELL,JOBSTATUS,EMPLOYEE_STATUS,NATIONALITY,SEX,EDUCATION,MOBILE_PHONE,FIX_PHONE,EMAIL,t.UPDATE_TIME,
        row_number() over (partition by EMPLOYEE_NAME order by t.UPDATE_TIME) rn
 from SJHL_ZH.NZWOT_TOP_EMPLOYEE t
     left join NZWOT_TOP_USER a on a.EMPLOYEE_ID = t.EMPLOYEE_ID
     inner join (select org_id, org_name, parent_org_id, org_type, name_full_path, update_time from sjhl_zh.nzwot_top_organization
          where state = 1 and regexp_like(name_full_path, '(变电管理所|输电管理所|试验研究所)')
          start with parent_org_id = ( select org_id from sjhl_zh.nzwot_top_organization
          where name_full_path = '中国南方电网有限责任公司/广东电网有限责任公司/珠海供电局' and state = 1 and org_level = 3 ) connect by prior org_id = parent_org_id
          union
          select org_id, org_name, null, org_type, name_full_path, update_time from sjhl_zh.nzwot_top_organization
          where name_full_path = '中国南方电网有限责任公司/广东电网有限责任公司/珠海供电局' and state = 1 and org_level = 3) b on b.ORG_ID = a.ORG_ID) tb
          where tb.rn = 1;