Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.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
使用“或”语法的mysql查询_Mysql_Sql_Database - Fatal编程技术网

使用“或”语法的mysql查询

使用“或”语法的mysql查询,mysql,sql,database,Mysql,Sql,Database,简单的mysql问题我正在尝试基于四个值的条件编写一个查询,但是它似乎不起作用,下面是一个示例和查询: select * from table_1 where c=0 d=0 a=0 u=0 or c=1 d=1 a=1 u=1 where c+d+a+u = 0 or c*d*a*u = 1 您的WHERE逻辑不正确: select * from table_1 where (c=0 and d=0 and a=0 and u=0) or (c=1 and d=1 and a=1 a

简单的mysql问题我正在尝试基于四个值的条件编写一个查询,但是它似乎不起作用,下面是一个示例和查询:

select * from table_1 where c=0 d=0 a=0 u=0 or c=1 d=1 a=1 u=1
where c+d+a+u = 0 or c*d*a*u = 1
您的WHERE逻辑不正确:

select * 
from table_1 
where (c=0 and d=0 and a=0 and u=0) 
or (c=1 and d=1 and a=1 and u=1)
您需要在括号中将语句组合在一起,并且对于需要组合在一起的任何条件仍然使用and。

您的WHERE逻辑不正确:

select * 
from table_1 
where (c=0 and d=0 and a=0 and u=0) 
or (c=1 and d=1 and a=1 and u=1)

您需要将语句组合在括号中,并且对于需要组合在一起的任何条件仍然使用and。

或者,如果它们始终为0和1,您可以使用技巧缩短查询:

select * from table_1 where c=0 d=0 a=0 u=0 or c=1 d=1 a=1 u=1
where c+d+a+u = 0 or c*d*a*u = 1

或者,如果它们始终为0和1,则可以使用技巧缩短查询:

select * from table_1 where c=0 d=0 a=0 u=0 or c=1 d=1 a=1 u=1
where c+d+a+u = 0 or c*d*a*u = 1

我的直接回答是:从表_1中选择*,其中c=0,d=0,a=0,u=0,或者c=1,d=1,a=1,u=1,但这似乎太简单了……您似乎不熟悉基本的SQL语法。谢谢,我不认为任何问题是愚蠢的,唯一愚蠢的问题是没有被问到,所以作为一个学习者,我不知道这个问题在哪里会被低估,不过,我非常感谢大家的帮助。我的即时反应是:从表_1中选择*,其中c=0和d=0和a=0和u=0,或者c=1和d=1和a=1和u=1,但这似乎太简单了……似乎您不熟悉基本的SQL语法。谢谢您,我不认为任何问题是愚蠢的,唯一愚蠢的问题是没有被问到的问题,因此作为一名学习者,我不知道该问题在哪里被降级,但是我非常感谢大家的帮助。Parens可能是一个很好的做法,但这里没有严格的必要,因为和优先于或。Parens可能是一个很好的做法,但这里并没有严格的必要,因为AND优先于OR。