这个MySQL查询有什么问题,它有一个带有连接的子查询,应该链接来自3个表的数据?

这个MySQL查询有什么问题,它有一个带有连接的子查询,应该链接来自3个表的数据?,mysql,join,subquery,Mysql,Join,Subquery,我有一个游戏,用户参与组织的比赛和竞赛,每天的比赛,比赛举行每隔几年。分数是基于他们对第二天运动成绩的预测程度 我要执行的查询涉及三个表。一个表包含竞赛元数据(如名称和年份),另一个表按MatchId链接竞赛,另一个表包含每个用户和MatchId的每日排名 我希望得到一个结果,通过MatchId给出平均分数,以及竞赛元数据(通过充当中介的Matches表)。这三个表格是: DailyStandings: -UserId (int) -MatchId (int) -MatchScore (doub

我有一个游戏,用户参与组织的比赛和竞赛,每天的比赛,比赛举行每隔几年。分数是基于他们对第二天运动成绩的预测程度

我要执行的查询涉及三个表。一个表包含竞赛元数据(如名称和年份),另一个表按MatchId链接竞赛,另一个表包含每个用户和MatchId的每日排名

我希望得到一个结果,通过MatchId给出平均分数,以及竞赛元数据(通过充当中介的Matches表)。这三个表格是:

DailyStandings:
-UserId (int)
-MatchId (int)
-MatchScore (double)
-"UserId, MatchId" is the primary key

Matches:
-MatchId (int, primary key)
-ContestId (int)

Contests:
-ContestId(int, primary key)
-Name ( varchar(50) )
-Year (smallint)
我正在尝试以下查询:

SELECT DailyStandings.MatchId, AVG(DailyStandings.MatchScore) AS Average, ContestInfo.Name
FROM DailyStandings
INNER JOIN{
 SELECT * FROM Matches
 LEFT JOIN Contests
 ON Matches.ContestId=Contests.ContestId
} ContestInfo
ON DailyStandings.MatchId=ContestInfo.MatchId
WHERE 1
GROUP BY DailyStandings.MatchId ORDER BY DailyStandings.MatchId ASC
请注意,我不确定我是否应该在这里使用内部联接或左联接,但这两种联接似乎都不起作用

内部联接中的子查询工作正常,如果我去掉了子查询(以及SELECT中的contestinginfo.Name),那么主查询工作正常

也许我犯了一个明显的错误,但我的错误是什么?

试试这个:

SELECT DailyStandings.MatchId, AVG(DailyStandings.MatchScore) AS Average,
Matches.MatchId, Matches.ContestId 
FROM DailyStandings 
INNER JOIN Matches 
ON DailyStandings.MatchId=Matches.MatchId
Inner Join Contests 
ON Contests.ContestId=Matches.ContestId
WHERE 1 /* Not sure what is "1". Try removing this first and then execute                                        the query. */
GROUP BY DailyStandings.MatchId ORDER BY DailyStandings.MatchId ASC
试试这个:

SELECT DailyStandings.MatchId, AVG(DailyStandings.MatchScore) AS Average,
Matches.MatchId, Matches.ContestId 
FROM DailyStandings 
INNER JOIN Matches 
ON DailyStandings.MatchId=Matches.MatchId
Inner Join Contests 
ON Contests.ContestId=Matches.ContestId
WHERE 1 /* Not sure what is "1". Try removing this first and then execute                                        the query. */
GROUP BY DailyStandings.MatchId ORDER BY DailyStandings.MatchId ASC

@特里斯坦欢迎并很高兴能帮助你。@特里斯坦欢迎并很高兴能帮助你。