gpt4 book ai didi

mysql - 使用 MySQL 的 LIKE 和记录过滤没有变化

转载 作者:行者123 更新时间:2023-11-29 09:04:41 27 4
gpt4 key购买 nike

我有我的SQL,但WHERE子句是我遇到的问题,因为用运算符过滤记录似乎并没有过滤记录,而是在不应该过滤的时候提取记录,我需要使用 LIKE/REGEXP 来选取记录,然后通过将 true 的记录包含到 = 语句中来缩小范围。

WHERE  rec.street_name REGEXP '[[:<:]]united[[:>:]]'
OR rec.city REGEXP '[[:<:]]united[[:>:]]'
OR rec.state REGEXP '[[:<:]]united[[:>:]]'
OR rec.country REGEXP '[[:<:]]united[[:>:]]'
OR rec.street_name LIKE 'united'
OR rec.city LIKE 'united'
OR rec.state LIKE 'united'
OR rec.country LIKE 'united'
AND rec.ad_type = 1
AND ( rec.num_rooms >= 15 AND rec.num_rooms IS NOT NULL )
AND rec.visible_listing = 1

此 WHERE 子句也不会过滤掉记录:

WHERE  rec.street_name REGEXP '[[:<:]]united[[:>:]]'
OR rec.city REGEXP '[[:<:]]united[[:>:]]'
OR rec.state REGEXP '[[:<:]]united[[:>:]]'
OR rec.country REGEXP '[[:<:]]united[[:>:]]'
OR rec.street_name LIKE 'united'
OR rec.city LIKE 'united'
OR rec.state LIKE 'united'
OR rec.country LIKE 'united'
AND ( rec.ad_type = 1 AND ( rec.num_rooms >= 15 AND rec.num_rooms IS NOT NULL) AND rec.visible_listing = 1 )

即使将 rec.num_rooms/rec.ad_type 更改为任何数字仍然不会改变任何内容。这是为什么?

最佳答案

在 OR 两边添加括号

WHERE  (rec.street_name REGEXP '[[:<:]]united[[:>:]]'
OR rec.city REGEXP '[[:<:]]united[[:>:]]'
OR rec.state REGEXP '[[:<:]]united[[:>:]]'
OR rec.country REGEXP '[[:<:]]united[[:>:]]'
OR rec.street_name LIKE 'united'
OR rec.city LIKE 'united'
OR rec.state LIKE 'united'
OR rec.country LIKE 'united' )

AND rec.ad_type = 1
AND rec.num_rooms >= 15
AND rec.num_rooms IS NOT NULL
AND rec.visible_listing = 1

关于mysql - 使用 MySQL 的 LIKE 和记录过滤没有变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7417429/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com