使用表中的ID,然后使用该表中的ID来获取数据SQL

时间:2017-05-03 05:16:05

标签: mysql database phpmyadmin

SELECT
    player.FirstName,
    player.LastName,
    team.teamName,
    TotalPoints,
    TotalRebounds,
    TotalAssists,
    TotalSteals,
    TotalBlocks
FROM playerstats
INNER JOIN player
    ON playerstats.PlayerID = player.PlayerID

我有一个名为player的表(玩家ID,名字,姓氏,团队ID) 表叫Team(teamID,teamName)。我有一个叫做playertat的桌子(有播放器ID)

我想列出名字,姓氏和球队以及得分,篮板等

我想使用playerID获取团队ID,然后列出团队名称......如果这有意义的话。不知道该怎么做。

2 个答案:

答案 0 :(得分:0)

在你的问题中,你没有表明每个玩家的牌桌数是否有多行,而你没有表明队列表的列可能是什么,但是假设玩家的牌桌是每个玩家有多行,并且你有一个团队表,你可以尝试一下。您需要替换正确的列名称:

SELECT
    player.FirstName,
    player.LastName,
    team.teamName,
    sum(points) as TotalPoints,
    sum(rebounds) as TotalRebounds,
    sum(assists) as TotalAssists,
    sum(steals) as TotalSteals,
    sum(blocks) as TotalBlocks
FROM playerstats
INNER JOIN player
    ON playerstats.PlayerID = player.PlayerID
JOIN team
    ON team.id = player.teamID
GROUP BY player.FirstName, player.LastName,team.teamName
ORDER BY player.FirstName, player.LastName,team.teamName;

答案 1 :(得分:0)

Select P.FirstName,P.LastName,t.teamName,s.TotalPoints 
from Player P
join Team t on P.TeamId=t.TeamId
join playerstats s on P.PlayerId=s.PlayerId