一个具有多个文件名的字段映射:MsAccess SQL

时间:2019-05-08 12:24:41

标签: sql ms-access

我无法将团队表比赛表结合起来,这样我就可以每年获得团队绩效的统计数据。

数据库架构

enter image description here

需要输出

enter image description here

1 个答案:

答案 0 :(得分:1)

删除您创建的表关系。它没有用。您需要的是这样的东西:

SELECT Teams.[TeamNameField], Year([Date]) AS MatchYear, [HomeYellowCardField] AS YellowCards FROM Matches INNER JOIN Teams ON Matches.HomeTeam=Teams.[TeamIDField]
UNION ALL
SELECT Teams.[TeamNameField], Year([Date]) AS MatchYear, [AwayYellowCardField] AS YellowCards FROM Matches INNER JOIN Teams ON Matches.AwayTeam=Teams.[TeamIDField]

将其保存为永久查询。以此为起点,达到最终目标应该容易得多。