select connect_by_root(old),new from table a start with not exists(select 1 from
table b where b.new=a.old) where connect_by_isleaf=1
connect by nocycle prior a.new=a.old
[Quote=引用 4 楼 minitoy 的回复:]
select connect_by_root(old),new from table a start with not exists(select 1 from
table b where b.new=a.old) where connect_by_isleaf=1
connect by prior a.new=a.old
[/Quote]
楼上快哦
WITH a AS(
SELECT '2010-1-1' rq,'XXX' yz,'YYY' mbz FROM dual
UNION ALL
SELECT '2010-5-1' ,'YYY' ,'ZZZ' FROM dual
UNION ALL
SELECT '2010-1-1' ,'AAA' ,'BBB' FROM dual
)
SELECT CONNECT_BY_ROOT(yz),mbz FROM a
WHERE CONNECT_by_isleaf=1
START with NOT EXISTS(select 1 from a b where b.mbz=a.yz)
CONNECT BY PRIOR mbz=yz
select connect_by_root(old),new from table a start with not exists(select 1 from
table b where b.new=a.old) where connect_by_isleaf=1
connect by prior a.new=a.old