pgsql模擬oracle的start with connect by查詢

with t as (select * from t_department where parent_id=0) select count(0) from t;  

with t1 as (select * from t_department),t2 as(select * from t_department where parent_id=0) 
select t1.* from t1,t2 where t2.id=t1.parent_id;


with recursive t as(select id,name,parent_id from t_department where id=1 union all select k.id,k.name,k.parent_id from t_department k,t where t.id=k.parent_id) select * from t;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章