【问题标题】:Select subset of records within the same table选择同一表中的记录子集
【发布时间】:2014-11-28 22:41:31
【问题描述】:

有一个表显示权限和某些对象的映射,即对象“obj1”具有“perm1”和“perm2”权限,“obj2”-“perm1”和“perm3”。

Permission_id Object_Id
  perm1      |   obj1
  perm2      |   obj1
  perm1      |   obj2
  perm3      |   obj2

问题是:如何获得应用于所有对象的权限子集? IE。 :

Permission_id 
    perm1     

【问题讨论】:

    标签: sql


    【解决方案1】:

    以下内容为此目的使用计数和聚合:

    select permission_id
    from permissionobjects po
    group by permission_id
    having count(distinct object_id) = (select count(distinct object_id) from permissionobjects);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-08
      • 1970-01-01
      • 2011-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-01
      • 2014-11-21
      相关资源
      最近更新 更多