-1

我有下面的代码,它通过一个表,每行都有一个表名和数字

例如

Barcelona | 3 | Milan   | 6
Inter     | 6 | Chelsea | 2
Barcelona | 8 | Madrid  | 2
Inter     | 2 | Parma   | 1

使用以下代码,我希望我的结果是

Barcelona 11 8 3
Inter 8 3 5

所以我得到了目标得分和差异但是我的查询适用于第一行但它不考虑第二行的差异

SELECT
    c.team1, 
    SUM(c.team1score) as GF,
    SUM(c.team2score) as GA,
    (c.team1score-c.team2score) as GD
FROM calendario AS c
GROUP BY c.team1

为什么会这样??

4

1 回答 1

1

你的问题不是很清楚,但也许你只需要取两个 SUM 值之间的差异,就像这样:

 SELECT c.team1, sum(c.team1score) as GF, sum(c.team2score) as GA, (sum(c.team1score)-sum(c.team2score)) as GD
 FROM calendario c
 group by c.team1
于 2012-04-07T21:43:40.213 回答