我有以下格式的数据。
Emp to_location from_location Vehicle
---------------------------------------------
1 A B Road
1 B C Ship
1 C D Air
1 X D Bus
需要输出为
Emp ToL FromL Vehicle
--------------------------
1 A D Air
我尝试使用Connect by
和Start with
,但结果如下。
Emp FromL ToL Path
--------------------------
1 B C Air
我需要输出为
Emp FromL ToL Path
--------------------------
1 D A Air
我构建的查询如下所示。
with t as
( select 1 emp, 'A' tloc, 'B' floc, 'Road' v from dual union all
select 1 emp,'B' tloc, 'C' floc, 'Ship' v from dual union all
select 1 emp,'C' tloc, 'D' floc, 'Air' v from dual union all
select 1 emp,'X' tloc, 'D' floc, 'Bus' v from dual
)
select emp,
connect_by_root floc from_loc,
tloc to_location,
v,
CONNECT_BY_ISLEAF ch
from T
where CONNECT_BY_ISLEAF=1
CONNECT BY nocycle prior floc= tloc and prior emp=emp
AND PRIOR SYS_GUID() IS NOT NULL
START WITH tloc ='A'
有谁能纠正我遗漏的小东西,以获得正确的输出吗?TIA
1条答案
按热度按时间xlpyo6sf1#
我认为您的查询很好-您只需在执行时选择根元素即可
以便再让出