sql查询树状结构某节点下的所有子节点
作者:互联网
with cte_child(id,areaName,pid,level)
as
(
--起始条件
select id,areaName,pid,0 as level from erp_area
where id = 1 -- 优先列出第一节点查询条件
union all
--递归条件
select a.id,a.areaName,a.pid,b.level+1
from erp_area a
inner join
cte_child b
on ( a.pid=b.id)
)
select * from cte_child
标签:树状,child,pid,节点,areaName,sql,level,id,select 来源: https://www.cnblogs.com/lhr518/p/16494543.html