无法使此JOIN工作

时间:2014-08-20 15:33:38

标签: mysql sql join

基本上我的问题如下。我收到了这个问题:

select 
  ROUND(((SUM(1/Pl))/Count(*))*100, 1) as 'ExpectedWinrate', 
  Players.Pname as 'Player' 
from 
  Wins, Players 
where Code like CONCAT('%', Players.SC, '%') 
Group by Players.Pname 
Order by ROUND(((SUM(1/Pl))/Count(*))*100, 1) desc;

它按照我想要的方式工作(计算多人游戏中几个玩家在多场比赛中的预期胜率)。 我的问题是现在我想加入我从这个查询得到的另一个表中得到的表:

select 
  Count(*) as 'Wins', 
  Players.Pname as 'Player' 
from Players, Wins 
where Players.PNr = Wins.PNr 
group by Players.Pname 
order by Count(*) desc; 

据我所知,我必须使用JOIN,但我根本无法让它工作。 在alpha语言中,我想要做的是:

JOIN query_1 AND query_2 over PName;

我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

这样的东西?

SELECT a.'Player',a.'ExpectedWinrate',b.'Wins'
FROM(
SELECT  
  ROUND(((SUM(1/Pl))/Count(*))*100, 1) as 'ExpectedWinrate', 
  Players.Pname as 'Player' 
FROM 
  Wins, Players 
WHERE Code LIKE CONCAT('%', Players.SC, '%') 
GROUP BY Players.Pname) a
INNER JOIN 
(SELECT 
  Count(*) as 'Wins', 
  Players.Pname as 'Player' 
FROM Players, Wins 
WHERE Players.PNr = Wins.PNr 
GROUP BY Players.Pname 
ORDER BY Count(*) desc) b ON a.'Player' = b.'Player'