我在多个赛季的多场比赛中有多名球员(桌子:球员,锦标赛,赛季)。因此,两名球员之间的比赛必须参考特定比赛和特定赛季。
table match
id
season_id
tournament_id
player_home
player_away
让我们说,将球员分配给锦标赛以获得明显的好处可能是很自然的。我可以在赛季和锦标赛之间做一对多的比赛(打桌比赛),然后为比赛和球员做一个多对多的牌桌吗?
table competition
id
season_id
tournament_id
table competition_player
id
competition_id
player_id
table match
id
competition_id
player_home
player_away
或者有更简单/更好的方法来实现这一目标吗?
感谢您的任何建议。
答案 0 :(得分:0)
非常基本,但你仍然可以看到这种关系。 Here
<强>表格强>
<强>球员强>
--------------------------
|Id | Name | OtherInfo |
--------------------------
| 1 | John | Player Info |
--------------------------
| 2 | Tom | Player Info |
--------------------------
<强>四季强>
-----------------------------------
|Id | SeasonName | SeasonInfo |
-----------------------------------
|01 | MyFirstSeason | Season Info |
-----------------------------------
Tournements
------------------------------------
| Id | SeasonId | TournamentName |
------------------------------------
|001 | 01 | MyFirstTournament|
------------------------------------
<强>相遇强>
---------------------------------------
| Id | FirstPlayerId | SecondPlayerId |
---------------------------------------
| A | 1 | 2 |
---------------------------------------
<强>马成顺强>
-----------------------------------------------
| Id | TournamentId | EncounterId | MatchInfo |
-----------------------------------------------
|0001| 001 | A | Some Info |
-----------------------------------------------
你正在使用许多钥匙。你只需要退一步思考一下设计。我知道我拿了一些专栏,但这只是为了这个例子。我相信你明白把它们放回去了。我只想展示这些表之间的关系。
让我们暗示你只想要基本信息(再一次只是为了这个例子)
Select m.Id,
t.TournamentName,
s.SeasonName,
(SELECT pl.Name FROM Players pl
JOIN Encounters en ON pl.Id = en.FirstPlayerId
WHERE pl.Id = en.FirstPlayerId) AS [FirstPlayerName],
(SELECT pl.Name FROM Players pl
JOIN Encounters en ON pl.Id = en.SecondPlayerId
WHERE pl.Id = en.SecondPlayerId) As [SecondPlayerName],
m.MatchInfo
FROM Matchs m
JOIN Tournaments t ON m.TournamentId = t.Id
JOIN Encounters e ON m.EncounterId = e.Id
JOIN Seasons s ON t.SeasonId = s.Id