sql 根据parent查询所有子集

如果需要查询出  一个人的所有下级(子下级),我们可以使用这个存过

注意:查询所有的下级, 但是不包括自己!

 

Create PROC P_存储过程名字

@ID   int

as

with temp

as

( select * from es_Agents where BelongsAgentOrgID=@ID union all select a.* from es_Agents as a inner join temp as child on a.BelongsAgentOrgID = child.AgentsID )

select * from temp

 

posted on 2019-05-15 17:29  阿里正正  阅读(1056)  评论(0编辑  收藏  举报

导航