Aggiorna
Dopo aver visto il tuo aggiornamento, devi solo eliminare INIZIA CON.
Termina aggiornamento
CONNECT_BY_ROOT è quello che stai cercando
Questa affermazione
SELECT distinct RootBoss, Person FROM (
with employee as
(
Select 1 person , null boss from Dual
UNION Select 2 , 1 from dual
UNION Select 3 , 2 from dual
)
SELECT CONNECT_BY_ROOT boss RootBoss, person
FROM employee connect_by
connect by prior person = boss
ORDER BY person
) t
WHERE ROOTBOSS is not null
ORDER BY
RootBoss, Person
Uscite
ROOTBOSS PERSON
---------------------- ----------------------
1 2
1 3
2 3
Aggiungere SOMME e GRUPPI è piuttosto semplice