这种不就是求树节点吗? 求子节点 ------解决方案-------------------- with tb(HierarchyId,NodeName,ParentId)
as(
select 1 ,'CEO',0 union all
select 2 ,'经理1',1 union all
select 3 ,'经理2',1 union all
select 4 ,'主管1',2 union all
select 5 ,'主管2',2 union all
select 6 ,'主管3',3 union all
select 7 ,'主管4',3 union all
select 8 ,'职员1',4
),
source as(
select * from tb where nodename like '%管1%'
union all
select tb1.* from tb tb1,source s1 where tb1.parentid=s1.HierarchyId
)
select * from source