0

好吧,我的问题是有一个 SQL 语句并完成工作,但不是我想要的,我想按操作、类型、城市或房间搜索,只显示人们在查询中选择的内容,并使用我的代码搜索所有记录,

SQL 代码:

SELECT * 
FROM `inmuebles` 
WHERE 
    action = 'sell' 
    OR type = 'apartment' 
    OR city = 'Los Angeles' 
    AND rooms BETWEEN 2 AND 5

任何帮助不胜感激

4

2 回答 2

0
SELECT * 
FROM `inmuebles` 
WHERE 
(
  action = 'sell' 
  OR type = 'apartment' 
  OR city = 'Los Angeles' 
)
AND rooms BETWEEN 2 AND 5
于 2013-11-05T16:45:23.987 回答
0

您应该将 OR 更改为 AND,因为现在您的条件太宽松了。

SELECT * FROM `inmuebles` 
WHERE action = 'sell' 
AND type = 'apartment' 
AND city = 'Los Angeles') 
AND rooms BETWEEN 2 AND 5
于 2013-11-05T16:45:31.020 回答