简体   繁体   English

将 2 个内部连接查询合二为一

[英]Combining 2 inner join query as one

I am stuck trying to combine output from 3 tables into one single query.我试图将 3 个表中的 output 组合成一个查询。

Here are the table structure这是表结构

BL_PLAYERS BL_PLAYERS

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

BL_POINTS BL_POINTS

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

BL_LEAGUES_RANK BL_LEAGUES_RANK

series_id int(10) player_id int(10) rank smallint(6) series_id int(10) player_id int(10) rank smallint(6)
last_game smallint(6) true_score smallint(6) handicap smallint(6) last_game smallint(6) true_score smallint(6) 差点 smallint(6)
total_score 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这是我的 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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM