Sql Postgres查询以检索所有标志值均为false的行
我有多对多关系的用户到角色表。我需要检索对任何用户都没有特权(false)的所有角色Sql Postgres查询以检索所有标志值均为false的行,sql,postgresql,Sql,Postgresql,我有多对多关系的用户到角色表。我需要检索对任何用户都没有特权(false)的所有角色 若上面的查询至少有一行privileged为true,那个么它将检索记录,例如,对于User3,opr4为privileged false,但对于User2,它为true。所以查询结果应该忽略这个记录。我如何实现这个用例。非常感谢任何帮助使用聚合和bool\u或() 或者,如果您愿意: having count(*) filter (where not ur.privileged) = 0 select r
若上面的查询至少有一行privileged为true,那个么它将检索记录,例如,对于User3,opr4为privileged false,但对于User2,它为true。所以查询结果应该忽略这个记录。我如何实现这个用例。非常感谢任何帮助使用聚合和
bool\u或()
或者,如果您愿意:
having count(*) filter (where not ur.privileged) = 0
select r.rolename
from pam."role" r join
pam.user_role ur
on r.id =ur.role_id
group by r.rolename
having not bool_or(ur.privileged);
having count(*) filter (where not ur.privileged) = 0