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