MYSQL,忽略空格,标点符号,替换查询中的重音符号
我需要一种方法来使用包含省份缩写、全名和地区的词典,而不必为安大略省的每个可能的拼写错误添加条目。 表格如下:
state |name | territory
===================================
AB Alberta West
数据如下:
"Ontario,"
"ON,"
"ON"
"On"
" Ontario"
"Ontario "
" Ontario "
Quebec
Québec
QU
QB
Quebec,
I need a way to use my dictionary with province abbreviations, full names and territories without having to add an entry for every possible misspelling of Ontario.
Table is as such:
state |name | territory
===================================
AB Alberta West
Data is as such:
"Ontario,"
"ON,"
"ON"
"On"
" Ontario"
"Ontario "
" Ontario "
Quebec
Québec
QU
QB
Quebec,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不是您眼前问题的真正答案,但这就是标准化的目的。为省份制作另一个表格,然后将其链接到原始表格,而不是允许自由格式的文本。
或者,向输入添加触发器以强制收集的数据保持一定的一致性。 (至少修剪空格,使其全部向上,也许检查有效条目..等)
not a real answer for you immediate problem, but this is what normalization is for. make another table for provinces, and then link that to the original table instead of allowing freeform text.
alterantely, add a trigger tot he input to enforce some consistency to the data collected. (at least trim the spaces, make it all UPPER, maybe check for valid entries.. etc.)
只是一个想法,知道它不能用于您的所有数据库。
无论如何:使用
怎么样?
SELECT * FROM 表,其中名称类似于“%ontario%”
?Just an idea, knowing it can't be used for all your db.
Anyway: what about using
SELECT * FROM table WHERE name LIKE '%ontario%'
?对于OP来说有点晚了,但对于其他尝试进行松散匹配搜索的人来说,请查看 STRCMP() 和 SOUNDEX() ,详细信息如下:
http://www.madirish.net/node/85
A bit late for the OP, but for others trying to do loose match searches, check out STRCMP() and SOUNDEX() as detailed here:
http://www.madirish.net/node/85