1. 程式人生 > >postgresql遞迴

postgresql遞迴

WITH RECURSIVE org_table AS ( 
            SELECT
                 org_id,
                 parent_org_id
             FROM
                 member_org
             WHERE
                 org_id = T2.org_id
             UNION ALL 


             SELECT 
                 member_org.org_id,
                 member_org.parent_org_id
             FROM
                  member_org,
                  org_table
             WHERE
                  member_org.org_id = org_table.parent_org_id
         ) 
         SELECT
             org_table.org_id
         FROM
             org_table,