很难解释我的问题,但我会尽我所能......
我正在尝试从各种表格构建一个视图,但我想要两个额外的列" HomeTeamID"和#34; AwayTeamID"这会带来适当的ID,即使是针对该特定事件的其他市场。
我已附加数据以向您显示我想要实现的目标(电子表格here)
答案 0 :(得分:-1)
你必须加入2次,
SELECT HomeTeam.ID, AwayTeam.ID from xyz INNER JOIN Team as HomeTeam on Team.ID = HomeTeam.ID INNER JOIN Team as AwayTeam on Team.ID = AwayTeam.ID
答案 1 :(得分:-1)
认为我已经拥有它,但又遇到了另一个问题。如果我不在SELECT区域中包含HomeTeamID,则需要23秒。当我包含HomeTeamID时,我收到以下错误:
'无法为数据库'tempdb'中的对象'dbo.SORT临时运行存储:140737648001024'分配空间,因为'PRIMARY'文件组已满。通过删除不需要的文件,删除文件组中的对象,向文件组添加其他文件或为文件组中的现有文件设置自动增长来创建磁盘空间。 “
Visual Studio在Parallels内部的Windows 8.1中运行,由于限制,我只有1GB的备用磁盘空间。这些表本身共有大约50,000条记录(MDF / LDF文件只有40MB,所以我很难看出问题所在:/
SELECT DISTINCT
BetfairEvents.OpenDate AS EventDateTime,
MarketT.Name AS MarketType, HomeContractT.RunnderID AS HomeTeamID,
CompetitionsT.Name AS CompetitionName, ContractsT.ID AS ContractID, ContractsT.RunnerID AS SelectionID,
ContractsT.LayOdds AS Price, ContractsT.LayAvailable AS Available,
RunnerT.Name AS RunnerName
FROM BetfairEvents
INNER JOIN BetfairMarket MarketT ON MarketT.EventID = BetfairEvents.ID
INNER JOIN BetfairCompetitions CompetitionsT ON CompetitionsT.ID = MarketT.CompetitionID
INNER JOIN BetfairContract ContractsT ON ContractsT.MarketID = MarketT.ID
INNER JOIN BetfairRunner RunnerT ON RunnerT.ID = ContractsT.RunnerID
INNER JOIN BetfairMarketType MarketTypeT ON MarketTypeT.Name = MarketT.Name
INNER JOIN BetfairMarket HomeMarketT ON MarketT.EventID = BetfairEvents.ID
INNER JOIN BetfairContract HomeContractT ON HomeContractT.SelectionID = 1