我正在为 Xbox 上的虚拟曲棍球联赛开发统计跟踪网页。我已经为此工作了一段时间,并且已经完成了大部分工作,但是在显示某些信息时发现了一个问题。似乎选择了表中与我的 JOIN 匹配的第一行,而不是也通过 WHERE 条件选择它。我想要做的是有一个页面来显示游戏的得分。
IE,从下面的信息来看,第 1 场比赛将是“纽约在芝加哥”,最终结果应该是 NY-5,CHI-3。这样可行。我遇到的问题是当我显示第 3 场比赛“纽约芝加哥”时,它显示相同的统计数据,而不是 CHI-2 NY-4。
我在这里缺少什么,还是有更好的方法来做到这一点?我基本上希望我的 JOIN 执行以下操作..这就是我认为我在 WHERE 行中所做的事情。
JOIN GameStats GSA ON ((GSA.team_ID = gs.awayTeam_ID) AND (GSA.gameSchedule_ID = '" . $scheduleID . "')
JOIN GameStats GSH ON ((GSH.team_ID = gs.homeTeam_ID) AND (GSH.gameSchedule_ID = '" . $scheduleID . "')
任何帮助将不胜感激!
$sql="SELECT
away.name as AWAY_TEAMNAME,
away.ID as AWAY_TEAMID,
home.name as HOME_TEAMNAME,
home.ID as HOME_TEAMID,
gs.ID as GAMEID
GSA.GOALS AS AWAY_GOALS,
GSA.SHOTS AS AWAY_SHOTS
GSH.GOALS AS HOME_GOALS,
GSH.SHOTS AS HOME_SHOTS
FROM
GameSchedule gs
JOIN Team away ON away.ID = gs.awayTeam_ID
JOIN Team home ON home.ID = gs.homeTeam_ID
JOIN GameStats GSA ON GSA.team_ID = gs.awayTeam_ID
JOIN GameStats GSH ON GSH.team_ID = gs.homeTeam_ID
WHERE
gs.ID = " . $scheduleID;
Table: Team
-------------------
| ID | name |
-------------------
| 1 | New York |
| 2 | Chicago |
| 3 | Detroit |
| 4 | Boston |
-------------------
Table: GameStats
--------------------------------------------------
| ID | gameSchedule_ID | team_ID | goals | shots |
--------------------------------------------------
| 1 | 1 | 1 | 5 | 5 |
| 2 | 1 | 2 | 3 | 2 |
| 3 | 2 | 3 | 6 | 1 |
| 4 | 2 | 4 | 1 | 7 |
| 5 | 3 | 2 | 2 | 14 |
| 6 | 3 | 1 | 4 | 7 |
| 7 | 4 | 4 | 5 | 9 |
| 8 | 4 | 3 | 5 | 4 |
-------------------------------------------------
Table: GameSchedule
----------------------------------
| ID | awayTeam_ID | homeTeam_ID |
----------------------------------
| 1 | 1 | 2 |
| 2 | 3 | 4 |
| 3 | 2 | 1 |
| 4 | 4 | 3 |
| 5 | 2 | 4 |
| 6 | 1 | 3 |
----------------------------------