sql server递归

with cte as
(
select belongsAgent from [QPProxyDB].[dbo].[BS_ProxyInfo] where ProxyID = @ProxyID 
union all
select a.ProxyID from [QPProxyDB].[dbo].[BS_ProxyInfo] a join cte b on a.ProxyID = b.belongsAgent
)
select * from cte order by belongsAgent asc

 

ProxyID 父级
belongsAgent 子集


posted @ 2018-08-20 17:07  兰博丶专属  阅读(358)  评论(0编辑  收藏  举报