--查询部门及下属部门列表 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 --获取递归后的集合
结果:
需要了解更多数据库技术:SqlServer 递归查询,都可以关注数据库技术分享栏目—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/dtteaching/625563.html