postgres 遞歸查詢

說明

Postgres中有個 with recursive的查詢方式,可以滿足遞歸查詢(一般>=2層)

示例

WITH RECURSIVE t(department_id , department_name , level) AS (
 select department_id , department_name , 1 as level from sys_department where department_id = '10'
 UNION  
 SELECT s.department_id , s.department_name , t.level + 1 as level
  from t , sys_department as s
 where t.department_id = s.parent_id
)
SELECT * from t  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章