有一个表格显示权限和某些对象的映射,即对象' obj1'有' perm1'和' perm2'权限,' obj2' - ' perm1'和' perm3'。
Permission_id Object_Id
perm1 | obj1
perm2 | obj1
perm1 | obj2
perm3 | obj2
问题是:如何获取应用于所有对象的权限子集?即:
Permission_id
perm1
答案 0 :(得分:1)
以下为此目的使用计数和聚合:
select permission_id
from permissionobjects po
group by permission_id
having count(distinct object_id) = (select count(distinct object_id) from permissionobjects);