在我的数据库中,我有带有国家/地区代码的电话号码,看起来像
0044-123456
0044-123456
0014-123456
0014-123456
0024-123456
0024-123456
0034-123456
0044-123456
0044-123456
0024-123456
0034-123456
084-123456
084-123456
我想按国家/地区汇总数字,类似于此输出
0044 (2)
0024 (2)
0034 (1)
084 (2)
064 (5)
是否可以通过 SQL 查询来完成此操作?
最佳答案
尝试一下:
SELECT count(SUBSTR(phoneNumber, 1, LOCATE("-", phoneNumber)))
FROM tableName
GROUP BY SUBSTR(phoneNumber, 1, LOCATE("-", phoneNumber));
关于mysql查询问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2763477/