SELECT a.*
FROM tablename a
WHERE NOT EXISTS (SELECT 1 FROM tablename b WHERE b.Fid = a.id)
START WITH Fid = 0 CONNECT BY PRIOR id=a.Fid;

 

常用的做法:

id in (SELECT a.id
FROM tablename a
WHERE NOT EXISTS (SELECT 1 FROM tablename b WHERE b.Fid = a.id)
START WITH Fid = 0 CONNECT BY PRIOR id=a.Fid)

Copyright © 2024 zkx4213
Powered by .NET 9.0 on Kubernetes