【发布时间】:2020-02-18 20:12:31
【问题描述】:
有没有办法在 SQL 中将“United States of America”与“United States”匹配?
我在数据库中存储了名为“美国”的国家/地区。 下面的查询应该从数据库中检索名为“United States”的项目。
SELECT * FROM `countries` WHERE `name` LIKE '%United States of America%'
谢谢!
【问题讨论】:
有没有办法在 SQL 中将“United States of America”与“United States”匹配?
我在数据库中存储了名为“美国”的国家/地区。 下面的查询应该从数据库中检索名为“United States”的项目。
SELECT * FROM `countries` WHERE `name` LIKE '%United States of America%'
谢谢!
【问题讨论】:
这是你想要的吗?
where 'United States of America' like concat('%', name, '%')
【讨论】:
对于这种情况,您应该查看弹性搜索数据库。它具有部分过滤器的功能。
否则您可以通过动态 sql 执行以下操作:
或者,您可以按照@Gordon 所说的那样做一个更简单的一次性解决方案
【讨论】: