首页 > 代码库 > 7. Orcle树形结构(类似数据字典有父子类关系),查询末节点的所有记录

7. Orcle树形结构(类似数据字典有父子类关系),查询末节点的所有记录

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)

7. Orcle树形结构(类似数据字典有父子类关系),查询末节点的所有记录