空のテーブルを結合してkills_totalフィールドに追加すると、 kills_total の値がNULLと表示されます。
SELECT
alias.name alias, team.name team, sid.steam_id steam_id,
(SUM(ws1.kills) + SUM(ws2.kills) + SUM(spnr.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
LEFT JOIN weapon_stats_2 ws2 ON ws2.pickup_id = pickup.id AND ws2.player_id = player.id
LEFT JOIN spanner_stats spnr ON spnr.pickup_id = pickup.id AND spnr.player_id = player.id
WHERE pickup.logfile_name = 'srv-20130725-2151-log' GROUP BY player.id ORDER BY kills_total DESC
結果は次のとおりです。
SELECT
alias.name alias, team.name team, sid.steam_id steam_id,
(SUM(ws1.kills) + SUM(ws2.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
LEFT JOIN weapon_stats_2 ws2 ON ws2.pickup_id = pickup.id AND ws2.player_id = player.id
WHERE pickup.logfile_name = 'srv-20130725-2151-log' GROUP BY player.id ORDER BY kills_total DESC
これは、クエリから空のテーブルを削除したときの結果です。
spanner_statsテーブルに結合し、空の場合は何もしない (つまり、SUM(0))方法で、 ws1とws2の値は SUM() され、結合されている 3 番目のテーブルにシングルがない場合でもkills_totalに表示されます。行一致" thirdTable.pickup_id = pickup.id AND thirdTable.player_id = player.id" ?