我一直试图将3个表的输出合并为一个查询。

这是表格结构

BL_PLAYERS

player_id int(10)
League_id int(10)
player_name varchar(150)
性别tinyint(3)
initial_hc smallint(6)
total_score int(10)
total_games smallint(6)
current_hc smallint(6)
League_player tinyint(3)

BL_POINTS

series_id int(10)
player_id int(10)
点smallint(6)

BL_LEAGUES_RANK

series_id int(10)
player_id int(10)
排名smallint(6)
last_game smallint(6)
true_score smallint(6)
障碍smallint(6)
total_score smallint(6)

这是我的2条内部连接语句..它们看起来几乎相同...但是我找不到一种将其组合的方法,以便第一个sql将返回附加列,即BL_LEAGUES_RANK的sum(rn.total_score)

SELECT pl.player_id, pl.player_name, pl.gender, pl.league_player, SUM( pt.point ) AS total_points FROM `bl_players` pl  INNER JOIN `bl_points` pt ON pl.player_id = pt.player_id AND series_id =1 GROUP BY player_id ORDER BY total_points DESC

SELECT pl.player_id, pl.player_name, pl.gender, pl.league_player, SUM(rn.total_score) as total_pinfall FROM `bl_players` pl INNER JOIN `bl_leagues_rank` rn ON pl.player_id = rn.player_id AND series_id =1 GROUP BY player_id ORDER BY total_pinfall DESC


可能吗预先感谢您对此的任何投入...

最佳答案

我认为这应该有效。

SELECT pl.player_id, pl.player_name, pl.gender,
    pl.league_player, SUM( pt.point ) AS total_points
FROM bl_players pl, bl_points pt, bl_leagues_rank rn
WHERE pl.player_id = pt.player_id AND series_id =1
    AND pl.player_id = rn.player_id
GROUP BY player_id ORDER BY total_points DESC

10-08 01:54