查询出树数据结构中根节点的所有子孙节点

WITH RECURSIVE T AS (
SELECT ID, parent_sys_org_id
FROM public.sys_org
WHERE id = #{orgId}

UNION ALL

SELECT D.ID, D.parent_sys_org_id
FROM public.sys_org D
JOIN T ON D.parent_sys_org_id = T.ID
)
SELECT t.ID FROM T ;

你可能感兴趣的:(数据库)