语句尝试1:
它似乎忽视了一切,从任何地方获取产品,而不分国家
SELECT *
FROM products
WHERE `country` = 'America' AND
product = 'Product 1' AND
product = 'Product 2' AND
completed = 'complete'
语句2:
这样做的结果是返回0个结果,即使结果是假设存在的。
SELECT *
FROM products
WHERE `country` = 'America' AND
product = 'Product 1' OR
product = 'Product 2' AND
completed = 'complete'
1条答案
按热度按时间kdfy810k1#
您的第一个查询在逻辑上不正确,原因是
product = product 1 AND product = product 2
,where子句逐个筛选行,因此一行不能同时包含product列中的两个值。您的第二个查询有一个您介绍的问题
OR
如果产品2在另一个国家/地区的状态为“已完成”,则忽略国家/地区筛选器。要更正您的查询,您需要对您的产品进行分组OR
使用括号的条件(condition 1 or condition 2) and some other condition
```SELECT *
FROM products
WHERE
country
= 'America'AND (product = 'Product 1' OR product = 'Product 2')
AND completed = 'complete'
SELECT *
FROM products
WHERE
country
= 'America'AND product IN('Product 1','Product 2')
AND completed = 'complete'