简体   繁体   中英

How to count result from two columns in mysql

I have a prediction table including homescore and awayscore. I want to output all distinct predictions and how many instances of each prediction exists.

matchid    homescore    awayscore
 1         1            2
 1         1            0
 1         9            3
 1         2            0
 1         1            2
 1         1            0
 2         3            2
 2         2            2
...

I want this to output a table like this for matchid 1:

result    predictions
1-2       2           
1-0       2
9-3       1
2-0       1
SELECT 
    CONCAT(homescore, '-', awayscore) as result,
    COUNT(*) as predictions
FROM table
WHERE matched = 1
GROUP BY CONCAT(homescore, '-', awayscore);

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