1
假设您拥有此角色ID和权限ID表。 我想列出所有具有权限1,2但缺少权限3,4的角色。 角色可以有其他权限,这应该不重要。如果角色具有权限1,2,我只关心角色中缺少的权限3,4。所以下面的测试表的结果应该是角色3.报告具有某种权限但不是其他角色的所有角色
我想出了一个有很多“in”和“not in”的解决方案。询问是否有更好的方法。我稍后会发布我的解决方案。我不想改变思维过程。
Declare @test table
(
roleid int,
permissionid int
)
insert into @test values(1,1)
insert into @test values(1,2)
insert into @test values(1,3)
insert into @test values(1,4)
insert into @test values(1,5)
insert into @test values(1,8)
insert into @test values(1,9)
insert into @test values(2,1)
insert into @test values(2,2)
insert into @test values(2,3)
insert into @test values(2,4)
insert into @test values(2,10)
insert into @test values(2,7)
insert into @test values(3,1)
insert into @test values(3,2)
insert into @test values(3,11)
insert into @test values(3,18)
insert into @test values(4,18)
insert into @test values(4,3)
它。好的解决方案 – Tigran 2014-09-11 07:44:53