[WHITE] 어느 LEVEL 위치에서 그 예하소속 인원 가지고 오기

Posted by MD워시퍼
2010. 7. 30. 14:21 Study
728x90
SELECT SUPER_ORG_CD
      , ORG_CD
      , F_ORM_ORG_LINE(ORG_CD,'1',SYSDATE)
      , (SELECT COUNT(0) FROM V_PHM_EMP_C WHERE F_ORM_ORG_LINE(ORG_CD,'1',SYSDATE) LIKE F_ORM_ORG_LINE(TEST.ORG_CD,'1',SYSDATE)||'%') AS CNT
 FROM(select level AS VAL, ORG_CD, SUPER_ORG_CD, ORG_NM
  from ORM_ORG_C
start with SUPER_ORG_CD  is null
connect by PRIOR ORG_CD = SUPER_ORG_CD
  AND SYSDATE BETWEEN STA_YMD AND END_YMD
  ) TEST
  WHERE VAL = 4