postgre 查询同表中的,该节点写的所有子节点

SELECT catalogid, foldername, parentid, folderpath
  FROM public.ic_catalog;

--查询同表中的,该节点写的所有子节点
WITH RECURSIVE T(catalogid,foldername,parentid) AS(
    SELECT catalogid,foldername,parentid FROM ic_catalog WHERE catalogid =19400
    UNION ALL
  SELECT T1.catalogid,T1.foldername,T1.parentid
   FROM ic_catalog T1 JOIN T ON T1.parentid=T.catalogid  
)
SELECT catalogid,foldername,parentid FROM T

 

posted @ 2018-10-30 17:33  紫晶城  阅读(658)  评论(0编辑  收藏  举报