WHERE语句中的mySQL多重AND比较

时间:2017-04-04 13:55:39

标签: php mysql where-clause

我有以下mySQL语句,这是不正确的。

SELECT id, location__, image__, bedrooms, bathrooms, price__ 
FROM myTable 
WHERE LOWER(location__) REGEXP '.london.' 
AND (bedrooms >=2) 
AND (bathrooms == true) 
ORDER BY price__  DESC 
LIMIT 0,20;

如何格式化在PHP中工作的SQL查询,以便我可以比较卧室> 2和浴室> 2 AND ensuites = 1(即true)......等

2 个答案:

答案 0 :(得分:2)

您只需要使用AND添加条件,以满足您的要求。

SELECT id, location__, image__, bedrooms, bathrooms, price__ 
FROM myTable 
WHERE LOWER(location__) REGEXP '.london.' 
AND bedrooms >=2
AND bathrooms >=2 and ensuites = 1
ORDER BY price__  DESC 
LIMIT 0,20;

答案 1 :(得分:1)

您可能在浴室中使用了错误的SQL比较运算符。在SQL中,您可以使用单个等号进行比较:

SELECT id, location__, image__, bedrooms, bathrooms, price__ 
FROM myTable 
WHERE LOWER(location__) REGEXP '.london.' 
AND bedrooms >= 2 
AND bathrooms = 1 
ORDER BY price__  DESC 
LIMIT 0,20;

https://www.techonthenet.com/sql/comparison_operators.php