Актуализация
След като видите актуализацията си, трябва само да пуснете ЗАПОЧНЕТЕ С.
Край на актуализацията
CONNECT_BY_ROOT е това, което търсите
Това изявление
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
Изходи
ROOTBOSS PERSON
---------------------- ----------------------
1 2
1 3
2 3
Добавянето на СУМИ и ГРУПИ е доста лесно