我有下表:
CREATE TABLE Z_BOM2 (A VARCHAR2(4 CHAR), B VARCHAR2(4 CHAR));
Insert into Z_BOM2 (A, B) Values ('A', 'B');
Insert into Z_BOM2 (A, B) Values ('A', 'C');
Insert into Z_BOM2 (A, B) Values ('C', 'D');
Insert into Z_BOM2 (A, B) Values ('C', 'F');
Insert into Z_BOM2 (A, B) Values ('D', 'E');
COMMIT;
SELECT * FROM Z_BOM2;
A B
A C
C D
C F
D E
A是父母,B是孩子。
我想在查询中输入子值“E”和“F”,并且只为这两个应该是“A”的那些获得顶级父级。这是我正在使用的查询:
select SYS_CONNECT_BY_PATH (a,'/') as path, a, b, level, CONNECT_BY_ISLEAF AS leaf, CONNECT_BY_ROOT b top_level
from Z_BOM2
connect by prior a = b
start with b IN ('E', 'F');
它返回以下内容:
/D D E 1 0 E
/D/C C D 2 0 E
/D/C/A A C 3 1 E
/C C F 1 0 F
/C/A A C 2 1 F
为什么它没有返回正确的顶级父级?