如何计算mysql中两列的结果

时间:2014-07-12 15:29:34

标签: php mysql

我有一个预测表,包括主场得分和客场比分。我想输出所有不同的预测以及每个预测存在多少个实例。

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
...

我希望这为matchid 1输出这样的表:

result    predictions
1-2       2           
1-0       2
9-3       1
2-0       1

1 个答案:

答案 0 :(得分:2)

SELECT 
    CONCAT(homescore, '-', awayscore) as result,
    COUNT(*) as predictions
FROM table
WHERE matched = 1
GROUP BY CONCAT(homescore, '-', awayscore);
相关问题