Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.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
Postgresql Postgres查询问题_Postgresql - Fatal编程技术网

Postgresql Postgres查询问题

Postgresql Postgres查询问题,postgresql,Postgresql,我不知道为什么这个结构不起作用。这是我第一次在博士后工作,希望有人能帮助我 SELECT * FROM "friends" WHERE "from" = '1' OR "to" = '1' AND "status" = '1' SELECT * FROM "friends" WHERE ("from" = '1' OR "to" = '1') AND "status" = '1' 它返回所有值,其中“from”为1,“to”为1,而不是“status”为1的一个或另一个值 我希望这不会太令人

我不知道为什么这个结构不起作用。这是我第一次在博士后工作,希望有人能帮助我

SELECT * FROM "friends" WHERE "from" = '1' OR "to" = '1' AND "status" = '1'
SELECT * FROM "friends" WHERE ("from" = '1' OR "to" = '1') AND "status" = '1'
它返回所有值,其中“from”为1,“to”为1,而不是“status”为1的一个或另一个值

我希望这不会太令人困惑


谢谢。

OR运算符的优先级低于AND。因此,表达式的计算如下所示:

(
    "from" = '1'
)
OR
(
    "to" = '1'
    AND
    "status" = '1'
)
您可能想要的是: