happyqiang

博客园 首页 新随笔 联系 订阅 管理
1  with cte as 
2  ( 
3  select a.DepartCode,a.DepartName,a.ParentDepartCode from tbDeparts a where ParentDepartCode='2' 
4  union all  
5  select k.DepartCode,k.DepartName,k.ParentDepartCode  from tbDeparts k inner join cte c 
6  on c.DepartCode = k.ParentDepartCode 
7  )
8  select * from cte 

 

posted on 2019-07-19 15:13  妙堂传奇  阅读(1413)  评论(0编辑  收藏  举报