我想在 MySQL 中左侧或第一行的第一个匹配的四个字符上提取双记录。 如何进行选择?
id name
1 1111q
2 1111
3 1111asdfgg
4 2222
5 2222ag
6 1111au
7 3333
8 5555
类似于:
id name
2 1111
1 1111q
6 1111au
3 1111asdfgg
4 2222
5 2222ag
最佳答案
select distinct t.*
from the_table t
inner join the_table t2 ON left(t.name,4)=left(t2.name,4) and t.id<>t2.id
通过 LEFT 4 个字符连接到同一个表并排除相同的 ID
关于Mysql 在第一个匹配的字符上查找重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35934936/