现在我有两张表,分别称为 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。