--查询当前部门和下级子部门, levl为递归次数
with dep as(
select *,0 as levl from Department where ID=1
union all
select a.*,b.levl+1 from Department a,dep b where a.ParentsID=b.id
)
select * from dep
--仅查询下级子部门, levl为递归次数
with dep as(
select *,0 as levl from Department where ID=1
union all
select a.*,b.levl+1 from Department a,dep b where a.ParentsID=b.id
)
select * from dep where levl>0