对这个问题有点麻烦: 使用下面的两个表,创建一个子查询或连接语句,在Player_PROFILE表中显示所有由Fisher执行的球员的球员,球队和否。
我提出了以下SQL代码,但我不确定如何完成它或者它是否正确:
SELECT PLAYER_PROFILE.Player, PLAYER_PROFILE.Team,
PLAYER_PROFILE.No
FROM PLAYER_PROFILE
INNER JOIN PLAYER_DETAIL
ON......
答案 0 :(得分:1)
不是这个 - 或者我在你的问题中遗漏了什么
SELECT PLAYER_PROFILE.Player, PLAYER_PROFILE.Team, PLAYER_PROFILE.No
FROM PLAYER_PROFILE
INNER JOIN PLAYER_DETAIL ON PLAYER_PROFILE.Player=PLAYER_DETAIL.Player
WHERE PLAYER_DETAIL.Coach = 'Fisher';
答案 1 :(得分:1)
SELECT PLAYER_PROFILE.Player, PLAYER_PROFILE.Team,
PLAYER_PROFILE.No
FROM PLAYER_PROFILE
INNER JOIN PLAYER_DETAIL
ON PLAYER_PROFILE.Player = PLAYER_DETAIL.Player
WHERE PLAYER_DETAIL.Coach = "Fisher"
你对玩家名称进行内部联接(http://www.w3schools.com/sql/sql_join_inner.asp),因为你需要一些对每个玩家来说都是唯一的数据...通常这是某种ID(数字/ guid)但是在在你的数据的情况下,它是玩家的名字。
答案 2 :(得分:1)
由于两个表只有Player
作为公共字段,因此查询将为:
SELECT PLAYER_PROFILE.Player, PLAYER_PROFILE.Team,
PLAYER_PROFILE.No
FROM PLAYER_PROFILE
INNER JOIN PLAYER_DETAIL
ON PLAYER_PROFILE.Player = PLAYER_DETAIL.Player
WHERE PLAYER_DETAIL.Coach = 'Fisher'
说明:上述查询会根据PLAYER
名称加入两个表的结果,并会过滤Coach
Fisher
如果您可以更改表格结构,那么我建议您在两个表格中都有PLAERY_ID
字段,以便唯一标识播放器而不是Player
列。
答案 3 :(得分:0)
SELECT
`PLAYER_PROFILE`.`Player`,
`PLAYER_PROFILE`.`Team`,
`PLAYER_PROFILE`.`No`
FROM
`PLAYER_PROFILE`
INNER JOIN
`PLAYER_DETAIL`
ON
`PLAYER_DETAIL`.`Player`=`PLAYER_PROFILE`.`Player`
WHERE
`PLAYER_DETAIL`.`Coach`="Fisher";
不同的玩家可以拥有相同的名称,因此最好为每个玩家使用唯一的ID并加入这些值。