我得到了以下sql:
SELECT * FROM LISTING WHERE
paused = 0 and city = 3 or city = 1 or city = 2
and rent = 1 and bedrooms = 1 and type = 1
我的结果是:它符合city = 3 or city=1 or city=2
但它忽略了其余部分:and rent = 1 and bedrooms = 1 and type = 1
我希望结果包含多个城市,但需要满足要求:and rent = 1 and bedrooms = 1 and type = 1
,现在它只输出多个城市的结果,而不再按租借进行过滤,卧室,类型。
请帮助,谢谢。
答案 0 :(得分:1)
由于您使用多个OR
条件,因此最好使用IN
子句。
SELECT * FROM LISTING
WHERE paused = 0
AND city IN (1, 2, 3)
AND rent = 1
AND bedrooms = 1
AND type = 1
答案 1 :(得分:0)
您需要划分OR部分
SELECT * FROM LISTING WHERE
paused = 0 and (city = 3 or city = 1 or city = 2 )
and rent = 1 and bedrooms = 1 and type = 1
更好的方法是:
SELECT * FROM LISTING WHERE
paused = 0 and city IN (1,2,3)
and rent = 1 and bedrooms = 1 and type = 1
答案 2 :(得分:0)
将其更改为:
SELECT * FROM LISTING WHERE
paused = 0 and ( city = 3 or city = 1 or city = 2 )
and rent = 1 and bedrooms = 1 and type = 1;
OR
SELECT * FROM LISTING WHERE
paused = 0 and city IN (1,2,3)
and rent = 1 and bedrooms = 1 and type = 1;