我有桌子匹配,我需要目标总和。如果Match.Home_team='Tupesy'
我需要Match.Home_team='Tupesy'
的总和,sum
的其他Match.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');
答案 0 :(得分:1)
可能是这样的(SUM和CASE应该按相反顺序编写):
select Sum(case
when (Home_Team = 'Tupesy') then
Home_goals
else
Away_goals
end)
from Match
where (ID_match = '1')