SqlServer 递归查询
程序员文章站
2022-05-02 12:24:44
结果: ......
--查询部门及下属部门列表 with temp --递归 as (select id, code, name, parentid from [dbo].[aspsysdepartments] where id = 38 --查询当前部门 union all select b.id, --查询子部门 b.code, b.name, b.parentid from temp a inner join [dbo].[aspsysdepartments] b on b.parentid = a.id) select id, code, name, parentid from temp --获取递归后的集合
结果: