SQL Join - 查询错误

时间:2016-04-16 19:57:56

标签: sql sql-server join inner-join

所以我想展示最有经验的玩家,起初我会显示所有玩家和经验值,然后尝试只显示最大值。所以继承了表和查询本身的代码

CREATE TABLE Player    
(    
  Player_ID INTEGER CONSTRAINT pk_player PRIMARY KEY,    
  Pname VARCHAR(60),  
  DOB    VARCHAR(10),    
  Heightcm NUMBER(10),    
  Weightkg NUMBER(10),    
  Position VARCHAR(20),    
  Team_ID INTEGER CONSTRAINT fk_player REFERENCES Team(Team_ID)
)

CREATE TABLE PlayerCareer_Performance   
(    
  Player_Performance_ID INTEGER CONSTRAINT pk_PP PRIMARY KEY,    
  Player_ID INTEGER,    
  total_points NUMBER(10),    
  total_fouls NUMBER(10),    
  ExperiencePoints NUMBER(10),    
  CONSTRAINT fk_Pp FOREIGN KEY (Player_ID) REFERENCES Player(Player_ID)
)

这是表格代码,下面是查询:

SELECT PLAYER.PLAYER_ID,PLAYER.PNAME,PLAYERCAREER_PERFORMANCE.EXPERIENCEPOINTS    
FROM PLAYER    
JOIN PLAYERCAREER_PERFOMANCE    
ON PLAYERPERFROMANCE.PLAYER_ID = PLAYER.PLAYER_ID;

播放器在黄色下划线,并显示“与连接图的其余部分断开连接”

任何想法,任何人?我看不出它的解决方法:(

2 个答案:

答案 0 :(得分:1)

乍一看,您正在加入表PLAYERCAREER_PERFORMANCE,但加入了一个名为PLAYERPERFROMANCE (原文如此)的表格字段。这是一个错字吗?

此:

SELECT Player.Player_ID, Player.Pname, PlayerCareer_Performance.ExperiencePoints
FROM Player
JOIN PlayerCareer_Performance 
ON PlayerCareer_Performance.Player_ID = Player.Player_ID

似乎工作正常(刚纠正错字):check it at sqlfiddle

作为一般建议,保持代码一致......您正在使用不同的列格式(例如:ExperiencePoints vs total_points),并将所有SQL查询代码放入大写字母中很难阅读和找到拼写错误

答案 1 :(得分:0)

使用内部联接(更新以反映大众需求):

select p.player_id, p.pname, pcp.experiencepoiuts
from Player p
inner join PlayerCareer_Performance pcp on pcp.player_id = p.player_id