with t as ( select 1 group_id, '1001' code, '' up_code from dual union all select 1 group_id, '3001' code, '1001' up_code from dual union all select 1 group_id, '3002' code, '1001' up_code from dual union all select 1 group_id, '5001' code, '3001' up_code from dual union all select 1 group_id, '5002' code, '3002' up_code from dual union all select 2 group_id, '1001' code, '' up_code from dual union all select 2 group_id, '3001' code, '1001' up_code from dual union all select 2 group_id, '3002' code, '1001' up_code from dual union all select 2 group_id, '5001' code, '3001' up_code from dual union all select 2 group_id, '5001' code, '3002' up_code from dual ) select * from t where 1 = 1 and group_id = 1 start with t.up_code is null connect by prior t.code = t.up_code ;
위의 Data는 1 Group 과 2Group 이 같은Data를 가지고 있는데
그룹별로 계층구조를 나열하고 싶습니다.
1 1001
1 3001 1001
1 5001 3001
1 3002 1001
1 5002 3002
2 1001
2 3001 1001
2 5001 3001
2 3002 1001
2 5001 3002
가능한가요?