postgres递归查询所有子部门

WITH RECURSIVE T ( ID, parent_id,depart_name ) AS (
            SELECT
                A.ID,
                A.parent_id,
                a.depart_name
            FROM
                sys_depart A
            WHERE
                A.id = 'bcb9dc287fbe40178162a6f9c877f3ef' UNION ALL
            SELECT
                b.ID,
                b.parent_id ,
                b.depart_name
            FROM
                sys_depart b,
            T
            WHERE
                b.parent_id = T.id
            ) SELECT ID, parent_id as "pId",depart_name as "text" FROM T

 

上一篇:随堂笔记1


下一篇:mysql 中 group by 用法