mySQL WHERE 语句中的多个 AND 比较

mySQL multiple AND comparisons in WHERE statement

我有以下 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 AND 浴室 > 2 AND ensuites = 1(即 true)...等

您可能对浴室使用了错误的 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

您只需使用 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;