다중 트리 문제 0 2 2,772

by 손님 [SQL Query] tree [2011.02.11 14:07:46]


안녕하세요.
조회시 두개 이상의 트리 구조 데이타가 리턴 되는데,
트리를 만들때 CHNL별로 만들고 싶습니다.
고수님의 조언을 구합니다.
with t as
(select 1 id, 0 upper_id ,'10G' NM,'03' STAT,1 CHNL from dual
union all select 2, 1 ,'2.5G','01',1 from dual
union all select 3, 1 ,'2.5G','01',1 from dual
union all select 4, 2 ,'155M','03',1 from dual
union all select 5, 2 ,'155M','01',1 from dual
union all select 6, 3 ,'155M','03',1 from dual
union all select 7, 3 ,'155M','01',1 from dual
union all select 8, 4 ,'45M','01',1 from dual
union all select 9, 4 ,'45M','01',1 from dual
union all select 10, 6 ,'45M','04',1 from dual
union all select 11, 7 ,'45M','01',1 from dual

union all select 1, 0 ,'2,5G','03',2 from dual
union all select 2, 1 ,'155M','01',2 from dual
union all select 3, 1 ,'155M','03',2 from dual
union all select 4, 2 ,'45M','01',2 from dual
union all select 5, 3 ,'45M','01',2 from dual
union all select 6, 3 ,'45M','01',2 from dual
union all select 7, 2 ,'45M','04',2 from dual
union all select 8, 2 ,'45M','01',2 from dual
)
SELECT * FROM T
START WITH upper_id = 0
CONNECT BY PRIOR ID = UPPER_ID
ORDER SIBLINGS BY CHNL

by 마농 [2011.02.11 14:27:57]
SELECT *
FROM T
START WITH upper_id = 0
CONNECT BY PRIOR id = upper_id
AND PRIOR chnl = chnl
;

by 앗싸 [2011.02.11 14:37:02]
역시 마농님이시네요.
정말 정말 감사합니다.
언제 마농님 실력 근처라도 갈수 있을까요!!
좋은 시간되세요
댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입