我正在尝试使用connect by获取记录的最高父级
Select distinct parent_box_id,box_id,
LEVEL,
SYS_CONNECT_BY_PATH(box_id, '>') "lineage"
FROM box_lineage lineage
where lineage.position = 1
START WITH box_id='00112233 '
CONNECT BY box_id = PRIOR parent_box_id
ORDER SIBLINGS BY box_id;
结果
parent child level hierarchy
123456 789456 3 >00112233>963258>789456
789456 963258 2 >00112233>963258
963258 00112233 1 >00112233
我想要的只是
123456 789456 3 >00112233>963258>789456
我不知道最高级别是2,3,4 5,6
我尝试了
and level >=3
和level 1
,但我只获得了最低级别我在这里阅读了其他答案,但没有一个有效
最佳答案
将AND CONNECT_BY_ISLEAF = 1
添加到where子句。