start with, connect by 응용 문의. 0 2 2,055

by 김성수 [2013.05.20 18:24:24]


고수님들 아래 문제 해결 부탁드립니다.ㅠ_ㅠ
[기본테이블]
LOT NODE
A B
B C
C D
D E
E  

결과
Search : A

ROOT LOT
E A
E B
E C
E D
E E


Search : B
ROOT LOT
E B
E C
E D
E E

with a as
(
select 'A' LOT, 'B' NODE from dual
union all
select 'B' LOT, 'C' NODE from dual
union all
select 'C' LOT, 'D' NODE from dual
union all
select 'D' LOT, 'E' NODE from dual
union all
select 'E' LOT, '' NODE from dual

) select * from a;

by 아린 [2013.05.20 18:35:30]
SELECT CONNECT_BY_ROOT(lot) root, lot
  FROM a
-- WHERE LEVEL <= 3 
 START WITH node IS NULL
 CONNECT BY PRIOR lot = node
 ORDER BY lot 

by 채용근 [2013.05.20 18:41:56]
select MAX ( DECODE ( CONNECT_BY_ISLEAF, 1, LOT ) ) OVER ()
   , lot from a
START WITH lot = 'B'
    -- lot = 'A'
 CONNECT BY lot = PRIOR node
댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입