江湖救急,oracle换成sqlserver 语句怎么写啊
发布网友
发布时间:2022-04-12 09:16
我来回答
共1个回答
热心网友
时间:2022-04-12 10:46
用WITH来解决这种问题。
with cte as
(
select Id,Pid,DeptName,0 as lvl from Department
where Id = 2
union all
select d.Id,d.Pid,d.DeptName,lvl+1 from cte c inner join Department d
on c.Id = d.Pid
)
select * from cte
http://www.cnblogs.com/xqhppt/archive/2011/02/15/1955366.html