我无法尝试将 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 整数(10) player_id 整数(10) 点smallint(6)
BL_LEAGUES_RANK
series_id 整数(10)
player_id 整数(10)
排名 smallint(6)
last_game smallint(6)
true_score smallint(6)
障碍smallint(6)
total_score smallint(6)
这是我的 2 个内部连接语句..它们看起来几乎相同......但我找不到一种方法来组合它,以便第一个 sql 将返回额外的列,即来自 BL_LEAGUES_RANK 的总和(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
关于mysql - 将 2 个内连接查询合并为一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5846612/