简体   繁体   English

如何从mysql中的两列计算结果

[英]How to count result from two columns in mysql

I have a prediction table including homescore and awayscore. 我有一个预测表,包括homescore和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: 我希望它为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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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