日期:2014-05-16 浏览次数:20818 次
with t as(
select '1' id,'0' gid from dual
union all
select '2','0' from dual
union all
select '3','1' from dual
union all
select '4','3' from dual
union all
select '5','2' from dual
union all
select '6','3' from dual
)
select t.id, connect_by_root gid gid
from t
start with gid in (select gid from t)
connect by prior id = gid;
ID GID
-- ---
1 0
3 0
4 0
6 0
2 0
5 0
3 1
4 1
6 1
5 2
4 3
6 3
12 rows selected