如何找出MySQL中每个DISTINCT CONCAT的结果总数?
SELECT DISTINCT CONCAT (h, ' - ', a) AS ft FROM raw_score
这样可以给我一个像这样的结果
1 - 0
2 - 2
1 - 1
0 - 1
但我也想知道最终得分发生了多少次,例如1 - 0可能发生了10次
对于每个结果,我使用此
再次查询数据库SELECT COUNT(CONCAT(h, ' - ', a) AS ft_total)
FROM raw_score
WHERE ft_total = 'result_from_previous_query'
但它不起作用
非常感谢您的帮助
答案 0 :(得分:2)
select ft, count(*)
from (
SELECT DISTINCT CONCAT (h, ' - ', a) AS ft
FROM raw_score
) t
group by ft
或合并为一个查询:
SELECT CONCAT (h, ' - ', a) AS ft, count(*)
FROM raw_score
group by CONCAT (h, ' - ', a)