这是我的查询:
select id, name, admin_user_id
from companies
where id = "21-09-20181535.abc";
结果:
21,anand,9331
由于 id 列是自动递增的,因此我预计不会有结果,因为搜索字符串是字母数字。 我应该怎么做才能得到想要的结果?
最佳答案
显式转换将处理此问题:
select id, name, admin_user_id
from companies
where cast(id as char) = "21-09-20181535.abc";
但是,这不会使用 id
上的索引。
另一个选项是允许使用 LIKE
运算符不带通配符进行隐式转换:
select id, name, admin_user_id
from companies
where id LIKE "21-09-20181535.abc";
这与在字符类型上使用 =
运算符相同。
关于mysql - 搜索字符串时仅考虑初始数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52438536/