请问下面两个sql语句有什么区别,
我按照数据库写的下面的那个,并没有读懂第一个sql语句
有必要去学第一种吗?
insert into @tmp select Id,@Layer from MIX_单位 where Id in (
select OrgId from MIX_UserPrivilege where UserId='BE9EE1CC-1818-43FF-8F1E-02098A8F59ED'
)
while @@ROWCOUNT>0
begin
select @Layer=@Layer+1
insert into @tmp select Id,@Layer from MIX_单位 where ParentId in (
select Id from @tmp where Layer=@Layer-1
) and Id not in (
select Id from @tmp
)
end
select Id from MIX_机组 where 单位Id in (
select Id from @tmp
)
select Id from MIX_机组 where 单位Id in( select Id from MIX_单位 where ParentId in( select OrgId from MIX_UserPrivilege))