基于字符串的 MySQL 查询 [英] MySQL Query based on string
问题描述
这个问题在过去的 10 个小时里一直困扰着我.我们开始吧:
This query has been bothering me for the past 10 hours. Here we go:
我想与我提取的一些数据进行比较.我正在提取名称,我想删除相似的名称并且不让它们在查询中返回.
I want to do a comparison to some data I am pulling. I am pulling names and I want to remove names that are similar and have them not return in the query.
示例:
我有以下名字:
- 海边高地
- 海边 HGTS
- 塔拉迪加
- 托恩卡尔中心
- Tornkal 点击率
- 扬克斯
- 斑马线
我希望它像这样返回:
- 海边高地
- 塔拉迪加
- 托恩卡尔中心
- 扬克斯
- 斑马线
基本上我认为它应该是 substring(name, 0, 8) 来获取前 8 个字符,然后针对下一个条目运行这 8 个字符,如果它们匹配则忽略它.
Basically I think it should be substring(name, 0, 8) to get the first 8 characters then run that 8 characters against the next entry and if they match to ignore it.
也许我正在考虑深入了解这一点.任何可能有用的见解或概念将不胜感激.
Maybe I am thinking way to deep into this. Any insight or concepts that might work will be appreciated.
推荐答案
试试下面的:
如果字符串之间的差异与您在示例中解释的相似.
If the difference between strings is similar as you explained in example.
select names from tablename group by substring_index(names," ",1)
这篇关于基于字符串的 MySQL 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!