Combining 2 inner join query as one
I am stuck trying to combine output from 3 tables into one single query.
Here are the table structure
BL_PLAYERS
player_id int(10)
league_id int(10) player_name varchar(150) gender 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) point smallint(6)
BL_LEAGUES_RANK
series_id int(10) player_id int(10) rank smallint(6)
last_game smallint(6) true_score smallint(6) handicap smallint(6) total_score smallint(6)Here are my 2 inner join statements.. they look almost identical... but I cant find a way to combine it so that the first sql will return additional column which is the sum(rn.total_score) from BL_LEAGUES_RANK
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
Is it even possible? Thank you in advance for any input on this...
I think this ought to work....
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
精彩评论