0

如何找出 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'

但它不工作

非常感谢您的帮助

4

1 回答 1

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)
于 2012-10-05T11:03:37.097 回答