0

现在我有两张表,分别称为 Singles 和 Averages。

单打是:

PersonID (PK)
EventID (FK)
best
worldRank

平均值为:

PersonID (PK)
EventID (FK)
best
worldRank

我正在尝试合并这两个表。基本上,结果表应该是:

“合并是:

PersonID (PK)
EventID(FK)
bestSingle ('best' from Singles)
bestAverage ('best' from Averages)
worldRankSingle ('worldRank' from Singles)
worldRankAverage ('worldRank' from Averages)"

这就是我现在所拥有的。

SELECT  RanksAverage.[personId],
RanksAverage.[eventId],
RanksAverage.[best] AS 'averageBest',
RanksAverage.[worldRank] AS 'averageRank',
RanksSingle.best AS 'singleBest',
RanksSingle.worldRank AS 'singleRank'

FROM [cubing].[dbo].[WCA_export_RanksSingle] AS RanksSingle

JOIN [cubing].[dbo].[WCA_export_RanksAverage] AS RanksAverage
ON RanksAverage.personId = RanksSingle.personId

顺便说一句,我正在使用 SQL Server 2012。

4

1 回答 1

2

看起来你唯一缺少的JOIN是第二个标准event

JOIN [cubing].[dbo].[WCA_export_RanksAverage] AS RanksAverage
ON RanksAverage.personId = RanksSingle.personId
AND RanksAverage.eventId = RanksSingle.eventId

这只是一个假设,因为我们不知道您的数据是什么样的。

于 2013-03-09T18:42:30.573 回答