时间:2021-07-01 10:21:17 帮助过:2人阅读
递归上下级部门,获取相关的部门单位
with Temp1 as ( select GroupID,G_ParentID from sys_Group where GroupID={当前部门GroupID} union all select sys_Group.GroupID,sys_Group.G_ParentID from Temp1 inner join sys_Group on Temp1.G_ParentID=sys_Group.GroupID ), Temp2 as ( select GroupID,G_ParentID from sys_Group where GroupID={当前部门GroupID} union all select sys_Group.GroupID,sys_Group.G_ParentID from Temp2 inner join sys_Group on Temp2.GroupID=sys_Group.G_ParentID ) select GroupID from Temp1 union select GroupID from Temp2
sqlserver with as 双向递归
标签: