|
with t as(
select 'a' u, 'bj' b, 'sh' e from dual union all
select 'a' u, 'sh' b, 'gz' e from dual union all
select 'b' u, 'bj' b, 'wh' e from dual union all
select 'b' u, 'wh' b, 'hk' e from dual union all
select 'c' u, 'bj' b, 'nj' e from dual)
select u,max(sys_connect_by_path(e,'/'))
from t
connect by prior u=u and prior e=b
start with b not in(select e from t t1 where t.u=t1.u)
group by u; |
|