sql 树 递归

sql 树 递归

with SubQuery(No,Name,ParentNo) as (  
  select No,[Name],ParentNo from [Port_Dept] where No = '3' 
  union all  
  select A.No,A.Name,A.ParentNo   
  from [Port_Dept] A inner join SubQuery B  
    on A.No = B.ParentNo  
)  
select * from SubQuery  

 

你可能感兴趣的:(sql)