postgres递归语句
with RECURSIVE cte AS(
select a.id,a.parent_id from org_t a where a.ID=1
UNION ALL
select k.id,k.parent_id from org_t k inner join cte c on c.ID = k.parent_id
) select id from cte;
2.查找父节点
with RECURSIVE cte AS(
select a.id,a.parent_id from org_t a where a.ID=40
UNION ALL
select k.id,k.parent_id from org_t k inner join cte c on c.parent_id = k."id"
) select id from cte
以上是 postgres递归语句 的全部内容, 来源链接: utcz.com/z/532349.html