我的数据库中有两个表。一个是时间表,另一个是联盟球队表。 schedule表没有团队的名称,它只有他们的ID,但是team表有。
我用这段代码来加入表格
float volume_cm3 = 0, emptySpace_cm3 = 0;
int[] voxels = new int[2];
VoxelizationTest script= new VoxelizationTest();
voxels = script.Voxelize (GameObject.Find (pair.Value.name), 0.015f);
volume_cm3 = voxels[0] * Mathf.Pow(1.5f, 3);
emptySpace_cm3 = voxels[1] * Mathf.Pow(1.5f, 3);
Debug.Log ("Voxels object: " + voxels[0] + " VolumeCm3:
" + volume_cm3 + " emptySpaceCm3: " + emptySpace_cm3);
float shapeRelation = emptySpace_cm3 / (emptySpace_cm3
+ volume_cm3);
if(shapeRelation > mayor)
mayor = shapeRelation;
objectsShapeRelation.Add (pair.Value, shapeRelation);
正如您在本页http://2kolf.com/our-data/schedules-test.php所见,客队(左侧)是正确的,但主队的名称与客队相同。
我已尝试将代码更改为此 -
SELECT statsSchedules.*
, leagueTeams.logoId
, leagueTeams.cityName
, leagueTeams.displayName
FROM statsSchedules
JOIN leagueTeams
WHERE statsSchedules.homeTeamId
AND statsSchedules.awayTeamId=leagueTeams.teamId
ORDER BY statsSchedules.weekIndex ASC
但这没有任何回报。
答案 0 :(得分:1)
对于您拥有的每个唯一主键(PK)/外键(FK)关系;需要加入。
由于statsSchedules有两个FK到联盟队,你需要两个联盟队伍加入。
由于列名相同,我不建议别名;但桌子也加入了。
SELECT statsSchedules.*
, homeTeam.logoId homeLogoId
, homeTeam.cityName homeCityName
, homeTeam.displayName homeDisplayName
, awayTeam.logoId awayLogoID
, awayTeam.cityName awayCityName
, awayTeam.displayName awayDisplayName
FROM statsSchedules
INNER JOIN leagueTeams as homeTeam
ON statsSchedules.homeTeamId = homeTeam.TeamID
INNER JOIN leagueTeams as awayTeam
ON statsSchedules.awayTeamId = awayTeam.teamId
ORDER BY statsSchedules.weekIndex ASC
答案 1 :(得分:0)
如果你有两杯茶,你需要statsSchedules和leagueTeams之间的两个内部联接
SELECT
statsSchedules.*
, a.logoId
, a.cityName
, a.displayName
, b.logoId
, b.cityName
, b.displayName
FROM statsSchedules
INNER JOIN leagueTeams a ON statsSchedules.homeTeamId = a.teamId
INNER JOIN leagueTeams b ON statsSchedules.homeTeamId = b.teamId
ORDER BY statsSchedules.weekIndex ASC