0

我有表匹配,我需要目标总和。如果Match.Home_team='Tupesy'我需要总和,Match.Home_team='Tupesy'否则sumMatch.Away_goals

现在我有了这个,但完全错误:/

SELECT *,
    CASE (Match.Home_team)
        WHEN (Match.Home_team='Tupesy')THEN (SUM(Match.Home_goals))
        ELSE (SUM(Match.Away_goals))
        END
FROM Match
Where (Match.ID_match='1');
4

1 回答 1

1

可能是这样(SUM 和 CASE 应该以相反的顺序编写):

select Sum(case
             when (Home_Team = 'Tupesy') then
               Home_goals
             else 
               Away_goals 
           end)
  from Match
 where (ID_match = '1')
于 2013-06-19T07:31:45.367 回答