Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql Postgres查询以检索所有标志值均为false的行_Sql_Postgresql - Fatal编程技术网

Sql Postgres查询以检索所有标志值均为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

我有多对多关系的用户到角色表。我需要检索对任何用户都没有特权(false)的所有角色


若上面的查询至少有一行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