有没有更优雅的方法来做到这一点:
SELECT TOP (@NumOfGames)
(SUM(IIF(Fixture.HomeTeamID = @Team
,IIF(Fixture.Goals.FullTimeHomeGoals > Fixture.Goals.FullTimeAwayGoals
,1
,IIF(Fixture.Goals.FullTimeHomeGoals < Fixture.Goals.FullTimeAwayGoals, 0, 0.5)
) --IsHomeTeam
,IIF(Fixture.Goals.FullTimeAwayGoals > Fixture.Goals.FullTimeHomeGoals
,1
,IIF(Fixture.Goals.FullTimeAwayGoals < Fixture.Goals.FullTimeHomeGoals, 0, 0.5)
) --IsAwayTeam
)) / @NumOfGames) * 100 AS Result
FROM
Fixture.Fixture
INNER JOIN
Fixture.Goals ON Fixture.Goals.FixtureID = Fixture.Fixture.FixtureID
WHERE
HomeTeamID = @Team
OR
AwayTeamID = @Team
我非常讨厌 SUM 部分,必须有更好的方法来做到这一点。
用户将@NumOfGames 和@Team 作为参数输入到存储过程。然后它会检查目标表以查看球队是否赢、平或输。赢是 1 分,平局是 0.5,输是 0。我想输出这些数字的总和,除以 NumOfGames 并乘以 100 得到成功率。