简体   繁体   中英

MySQL Counting the number of distinct results

How do I find out the total number of results for each DISTINCT CONCAT in MySQL?

SELECT DISTINCT CONCAT (h, ' - ', a) AS ft FROM raw_score

This works and gives me a result like this
1 - 0
2 - 2
1 - 1
0 - 1

but I also want to know how many times that final score has happened eg 1 - 0 could have happened 10 times

For each result I am querying the database again with this

SELECT COUNT(CONCAT(h, ' - ', a) AS ft_total) 
FROM raw_score 
WHERE ft_total = 'result_from_previous_query'

but its not working

Many thanks for any help

select ft, count(*)
from (
   SELECT DISTINCT CONCAT (h, ' - ', a) AS ft 
   FROM raw_score
) t
group by ft

or merged into a single query:

SELECT CONCAT (h, ' - ', a) AS ft, count(*)
FROM raw_score
group by CONCAT (h, ' - ', a)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM