您试图执行不包含指定表达式的查询'匹配号码'作为聚合的一部分

时间:2014-03-11 20:11:00

标签: sql ms-access

我正在尝试运行此功能,但上面的错误消息仍在继续。我已经尝试了一切,但似乎没有用。请任何人帮忙!!!

SELECT tblGameResults.MatchNumber,
       Sum(tblPlayerStatistics.Fouls_Made) AS Fouls
FROM tblGameResults 
INNER JOIN tblPlayerStatistics ON tblGameResults.MatchNumber = tblPlayerStatistics.MatchNumber
WHERE (((tblGameResults.Date_Of_Game)=[Date_Of_Game]) 
  AND ((tblGameResults.Place_Of_Game)=[Place_Of_Game]));

1 个答案:

答案 0 :(得分:5)

您需要GROUP BY对聚合值进行分组:

SELECT 
  tblGameResults.MatchNumber,
  Sum(tblPlayerStatistics.Fouls_Made) AS Fouls
FROM 
  tblGameResults 
INNER JOIN 
  tblPlayerStatistics ON tblGameResults.MatchNumber = tblPlayerStatistics.MatchNumber
WHERE (((tblGameResults.Date_Of_Game)=[Date_Of_Game]) 
  AND ((tblGameResults.Place_Of_Game)=[Place_Of_Game]))
GROUP BY 
  tblGameResults.MatchNumber;