[英]MySQL - displaying two inner joins in separate columns
First of all I have this which returns the date of all the football games where 首先,我要返回所有足球比赛的日期
HomeShotsOnTarget(HST) = FullTimeHomeGoals(FTHG) HomeShotsOnTarget(HST)= FullTimeHomeGoals(FTHG)
or 要么
AwayShotsOnTarget(AST) = FullTimeAWayGoals(FTHG) AwayShotsOnTarget(AST)= FullTimeAWayGoals(FTHG)
SELECT MatchDate, HomeTeam, AwayTeam
FROM matches
WHERE HST=FTHG or AST=FTAG
This displays 显示
MatchDate | HomeTeam | AwayTeam
2003/08/23 17 32
2003/09/13 24 39
and so on and so on... 等等等等...
The numbers under HomeTeam and AwayTeam are the TeamCodes which are in another table called clubs which also has the teams real name. HomeTeam和AwayTeam下的数字是TeamCode,这在另一个表中称为clubs的表中也具有球队的真实姓名。
The following matches the TeamCode for the HomeTeam with the RealName in table clubs. 以下内容使桌椅中的HomeTeam的TeamCode与RealName匹配。
SELECT MatchDate, RealName
FROM club T1
INNER JOIN matches T2 ON T1.TeamCode = T2.HomeTeam
This displays 显示
MatchDate| RealName|
2003/08/23 Arsenal
2003/09/13 Blackburn
Etc... 等等...
So my problem is I can't seem to find a way that displays the RealName Under HomeTeam and AwayTeam instead of the TeamCode. 所以我的问题是我似乎找不到在HomeTeam和AwayTeam下显示RealName而不是TeamCode的方法。 Like this...
像这样...
MatchDate | HomeTeam | AwayTeam
2003/08/23 Arsenal Aston Villa
2003/09/13 Blackburn Man Utd
Maybe something like: 也许像:
SELECT MatchDate, homeTeam.RealName AS HomeTeam, awayTeam.RealName AS AwayTeam
FROM matches m
INNER JOIN club homeTeam ON (m.HomeTeam = homeTeam.TeamCode)
INNER JOIN club awayTeam ON (m.AwayTeam = awayTeam.TeamCode);
I use to put some meaning labels instead of just, T1
and T2
. 我过去
T1
放一些含义标签,而不只是T1
和T2
。
You just need to do another join to the club table for the Away Team, like this: 您只需要再次为客队加入俱乐部桌,如下所示:
SELECT MatchDate, T1.RealName AS HomeTeamName, T3.RealName AS AwayTeamName
FROM club T1
INNER JOIN matches T2 ON T1.TeamCode = T2.HomeTeam
INNER JOIN club T3 ON T3.TeamCode = T2.AwayTeam
You just have to join the Team-Table two times, try this query: 您只需两次加入团队表,请尝试以下查询:
SELECT
MatchDate,
T1.RealName,
T2.RealName
FROM
matches INNER JOIN club T1 ON (matches.HomeTeam = T1.TeamCode)
INNER JOIN club T2 ON (matches.AwayTeam = T2.TeamCode)
WHERE
HST=FTHG OR AST=FTAG
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.