pgsql/mysql 示例
with recursive p as
(select d.* from rel_department d WHERE parent_id = '437757263160172544' or id = '437757263160172544'
union
select d2.* from rel_department d2 inner join p on d2.parent_id = p.id
)
select id,name,parent_id from p
select * from rel_department where id in (
with recursive p as
(select d.* from rel_department d WHERE d.id = '436961948618350592'
union all
select d2.* from rel_department d2 inner join p on d2.parent_id = p.id
)
select id from p
)
orcale SQL递归
select * from department start with id='1001' connet by prior id=pid;