我正在为Xbox上的虚拟冰球联盟创建一个统计跟踪网页。我有基本的表格布局设置,但我正在努力如何创建允许我显示日程安排的查询。下面是我的基本表格布局,我想要做的是显示如下:
游戏1:
纽约vs芝加哥
底特律vs波士顿
第2场比赛:
波士顿vs纽约
芝加哥vs底特律
SELECT homeTeam.name AS HOME_TEAMNAME
FROM GameSchedule Sched
INNER JOIN GameStats GameStatsHome
ON Sched.ID = GameStatsHome.gameSchedule_ID
AND Sched.homeTeam_ID = GameStatsHome.team_ID
INNER JOIN Team homeTeam
ON homeTeam.ID = gameStatsHome.team_ID
我意识到我遇到的问题是试图为GameSchedule.awayTeam_ID和GameSchedule.homeTeam_ID拉取Team.name。但我一直无法弄清楚如何做到这一点。我觉得我很亲密......但话又说回来,我不知道我在做什么,并花了大约3天的时间试图找出这个问题。我想如果有人能指出我正确的方向,我应该对我需要的其余部分有所帮助......任何帮助都将不胜感激。
Table: Team
-----------------------------------------------------------
| ID | name | abbreviation | conference | division |
-----------------------------------------------------------
| 1 | New York | TMA | 1 | 1 |
| 2 | Chicago | TMB | 1 | 1 |
| 3 | Detroit | TMC | 1 | 1 |
| 4 | Boston | TMD | 1 | 1 |
-----------------------------------------------------------
Table: GameSchedule
------------------------------------------------
| ID | awayTeam_ID | homeTeam_ID | gameTime_ID |
------------------------------------------------
| 1 | 1 | 2 | 1 |
| 2 | 3 | 4 | 1 |
| 3 | 4 | 1 | 2 |
| 4 | 2 | 3 | 2 |
------------------------------------------------
Table: GameStats
------------------------------------------
| ID | gameSchedule_ID | team_ID | goals |
------------------------------------------
| 1 | 1 | 1 | 5 |
| 2 | 1 | 2 | 3 |
| 3 | 2 | 3 | 6 |
| 4 | 2 | 4 | 1 |
| 5 | 3 | 1 | 2 |
| 6 | 3 | 4 | 5 |
------------------------------------------
答案 0 :(得分:0)
这将为您提供两个名称
SELECT
away.Name as AwayTeam,
home.Name as HomeTeam
FROM
Game_Schedule gs
JOIN Team away ON t.ID = gs.AwayTeam_ID
JOIN Team home ON t.ID = gs.HomeTeam_ID
你可以在这些连接中做任何你想做的事情!