0

我在这里遇到了一个问题:运行以下查询时,我只返回一行,即使它应该返回“在皮卡中找到的每个玩家、他的昵称、他效力的球队、他的 ID 和他的总击杀数在接球(比赛)期间犯下“

SELECT alias.name alias, team.name team, sid.steam_id steam_id, 
      SUM(kills) kills_total 
FROM pickup
    JOIN player ON player.pickup_id = pickup.id
    JOIN team ON player.team_id = team.id
    JOIN sid ON player.sid_id = sid.id
    JOIN alias ON player.alias_id = alias.id
    JOIN weapon_stats_1 ws1 ON ws1.pickup_id = pickup.id AND ws1.player_id = player.id
WHERE pickup.logfile_name = 'logfilename'

Weapon_stats_1看起来:桌子

为了说明它更具可读性,它可以如下所示:

pickup_id     player_id    weapon_id    kills    teamkills
logfilename1  0:0:1        Shotgun      12       2
logfilename1  0:0:1        RPG          19       0
logfilename1  0:0:2        Grenade      5        8

我想要做的是通过使用SUM()求和来获取总击杀数,并将其作为结果列添加到上面的查询中。对于这个例子,它应该返回类似于:

alias        team   steam_id    kills_total
nickname1    Red    0:0:1       31
nickname2    Blue   0:0:2       5

当我删除JOIN Weapon[...]行时,查询会返回我想要的结果 - 在此特定情况下,pickup.logfile_name = 'logfilename'看起来像:

结果

我不明白我做错了什么以及为什么当我JOIN Weapon_stats_1 ws1 [...]查询只返回一行(一个玩家)。我如何实现我想要做的事情?

问候

4

1 回答 1

0
SELECT alias.name alias, team.name team, sid.steam_id steam_id, 
      SUM(kills) kills_total 
FROM pickup
    JOIN player ON player.pickup_id = pickup.id
    JOIN team ON player.team_id = team.id
    JOIN sid ON player.sid_id = sid.id
    JOIN alias ON player.alias_id = alias.id
    LEFT JOIN weapon_stats_1 ws1 ON ws1.pickup_id = pickup.id AND ws1.player_id = player.id
WHERE pickup.logfile_name = 'logfilename' GROUP BY player.id, pickup.id

credits to @otzy

于 2013-07-25T22:33:51.403 回答