当colum值为true或1

时间:2017-03-20 15:18:51

标签: sql-server select count

我有这个数据库。 image

稍后我在表PlayerMatch中添加了一些列(时间(发生的时候),YellowCard,RedCard)。

在将此列添加到数据库之前,此SELECT工作并计算结果如下:

SELECT A.MatchDate, B1.Name AS HOMETEAM, C1.Goal AS GOAL_HOME, C2.Goal AS GOAL_AWAY, B2.Name AS AWAYTEAM
 FROM Match A
 INNER JOIN Team AS B1 ON A.HomeTeamId = B1.TeamId
 INNER JOIN Team AS B2 ON A.AwayTeamId = B2.TeamId
 LEFT JOIN (SELECT MatchId, TeamId, COUNT(Goal) AS Goal
            FROM PlayerMatch 
            INNER JOIN Players ON Players.PlayerId = PlayerMatch.PlayerId
            GROUP BY MatchId, TeamId) C1 ON A.MatchId = C1.MatchId AND A.HomeTeamId =C1.TeamId
 LEFT JOIN (SELECT MatchId, TeamId, COUNT(Goal) AS Goal
            FROM PlayerMatch 
            INNER JOIN Players ON Players.PlayerId = PlayerMatch.PlayerId
            GROUP BY MatchId, TeamId) C2 ON A.MatchId = C2.MatchId AND A.AwayTeamId =C2.TeamId

所以在我得到这样的输出之前:01.01.2001. Bayern 2 2 Barcelona

现在这个SELECT无法正常工作。它甚至在Goal = NULL时计算目标,所以我得到了错误的结果。我怎么能纠正这个?

0 个答案:

没有答案