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