sql 查询树状结构某节点(44)的上级所有根节点
作者:互联网
with cte_child(id,areaName,pid)
as
(
--起始条件
select id,areaName,pid from erp_area
where id = 44 --列出子节点查询条件
union all
--递归条件
select a.id,a.areaName,a.pid
from erp_area a
inner join
cte_child b --执行递归
on a.id=b.pid
)
select * from cte_child;
标签:--,44,child,pid,节点,areaName,sql,id,select 来源: https://www.cnblogs.com/lhr518/p/16494549.html