分层查询将所有子项作为行
Hierarchical query get all children as rows
数据:
ID PARENT_ID
1 [null]
2 1
3 1
4 2
想要的结果:
ID CHILD_AT_ANY_LEVEL
1 2
1 3
1 4
2 4
我试过 SYS_CONNECT_BY_PATH,但我不明白如何将它的结果转换成 "inline view",我可以将其用于 JOIN 与 main table.
select connect_by_root(id) id, id child_at_any_level
from table
where level <> 1
connect by prior id = parent_id;
数据:
ID PARENT_ID
1 [null]
2 1
3 1
4 2
想要的结果:
ID CHILD_AT_ANY_LEVEL
1 2
1 3
1 4
2 4
我试过 SYS_CONNECT_BY_PATH,但我不明白如何将它的结果转换成 "inline view",我可以将其用于 JOIN 与 main table.
select connect_by_root(id) id, id child_at_any_level
from table
where level <> 1
connect by prior id = parent_id;