数据库教程:SqlServer 递归查询

结果: …

--查询部门及下属部门列表    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 递归查询

 

需要了解更多数据库技术:SqlServer 递归查询,都可以关注数据库技术分享栏目—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/dtteaching/625563.html

(0)
上一篇 2021年5月25日
下一篇 2021年5月25日

精彩推荐