我有一个包含 VARCHAR(255)
列和一个 numeric(15, 2)
列的表。
如果我执行此搜索,它会起作用:
select title, cost, pageUrl
from products
where cost between 100 and 125
;
如果我执行此搜索查询,它会起作用:
select title, cost, pageUrl
from products
where title like '%something%'
or pageUrl like '%something%'
;
但是当我组合它们时,它会忽略数字过滤器:
select title, cost, pageUrl
from products
where cost between 100 and 125
and title like '%something%'
or pageUrl like '%something%';
我尝试了几种不同的组合查询变体,但我一直遇到同样的问题。任何指导将不胜感激。
最佳答案
你应该使用括号:
select title, cost, pageUrl
from products
where cost between 100 and 125
and (title like '%something%' or pageUrl like '%something%');
否则,数字过滤器将与第一个 like 谓词组合,并单独评估第二个 like 谓词。
可以查看Operator Precedence如果您愿意,可以在手册中找到。
关于mysql - 将数字条件与 like 组合中断 MySQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31146425/