【发布时间】:2013-07-18 10:27:48
【问题描述】:
我有三个表:Players、PlayersArchive、Races。 Players 和 PlayersArchive 表的结构完全相同。
在 Players 和 PlayersArchive 中,我们有 PlayerID 和 Name。
在 Races 中,我们排成一行:
RaceID、Record1PlayerID、Record2PlayerID、Record3PlayerID、Record4PlayerID 和 Record5PlayerID
任务是选择整个 Races 表,但它应该返回他们的名字而不是玩家 ID 字段。
例如:
Races table:
RaceID: 1
Record1PlayerID: 2
Record2PlayerID: 1
Record3PlayerID: 0
Record4PlayerID: 0
Record5PlayerID: 0
Players table:
PlayerID: 1
Name: Jhon
PlayersArchive table:
PlayerID: 2
Name: Jack
result:
1 Jack Jhon NULL NULL NULL
【问题讨论】:
-
你可以通过左连接和谷歌搜索来实现这一点
-
如果players和playersArchive表基本相同,为什么要分开呢?
-
(接着@fancyPants 所说的......)除非您期待 大量 数据(即使那样,也有一些扩展方法 - 您是否记得为您在连接中使用的字段添加索引?),通过将播放器拆分到单独的存档表中,您使事情变得比需要的更复杂。