row_id | area |teamleader
1 | 1234-Asia | Joe
2 | 12345-Europe | Juan
3 | 123456-UK | Ple
和 F12
row_id| eacode
1 | 1234
2 | 12345
3 | 1234
正如你所看到的,我希望使用类似%匹配eacode和区域并计算多少eacode。
我想在php中使用这样的东西
eacode| area | count | teamleader
1234 | Asia | 2 | Joe
12345 | Europe| 1 | Juan
抱歉我的英文不好
答案 0 :(得分:2)
SELECT eacode, substr(area, locate('-', area) + 1) area, count(*) `count`, teamleader
FROM f12
JOIN areas2013 ON area like CONCAT(eacode, '-%')
GROUP BY eacode
答案 1 :(得分:1)
Barmar的答案很好我只是稍微调整了一下以获得您所要求的确切输出:
SELECT eacode, SUBSTRING_INDEX(SUBSTRING_INDEX(area, '-', 2), '-', -1) as area, count(*) `count`, teamleader
FROM f12
JOIN areas2013 ON area like CONCAT(eacode, '-%')
GROUP BY eacode