sql 递归(应用场景:组织树)

发布时间 2023-11-13 11:27:53作者: LiXiang98
with cte as
        (
            select  *, 0 as level from Organization where  ParentID=''
            union all
            select d.*,level + 1 from cte c 
            inner join Organization  d    on c.ID = d.ParentID
        )
        select a.* from cte a