我有一个预测表,包括主场得分和客场比分。我想输出所有不同的预测以及每个预测存在多少个实例。
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
答案 0 :(得分:2)
SELECT
CONCAT(homescore, '-', awayscore) as result,
COUNT(*) as predictions
FROM table
WHERE matched = 1
GROUP BY CONCAT(homescore, '-', awayscore);