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