#sql递归写法
##由父节点不断向下查询
with etc as(
select 0 node, orgcode, orgName
from org_def
where orgcode = @orgcode
union all
select a.node + 1, b.orgcode, b.orgName
from etc a
inner join org_def b
on a.orgcode = b.parentOrgCode
)
##由子节点不断向上查询
with etc as(
select 0 node, orgcode, orgName, parentOrgCode
from org_def
where orgcode = @orgcode
union all
select a.node + 1, b.orgcode, b.orgName, b.parentOrgCode
from etc a
inner join org_def b
on a.parentOrgCode = b.orgcode
)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交