0

我有一个查询,以获取每个游戏的当前玩家数量的游戏,按玩家填充的玩家插槽百分比的度量来排序。

它是这样的:

SELECT 
  g.* , COUNT( p.ID ) NUM_OF_PLAYERS 
FROM 
  games g, 
  players p
WHERE  
  g.ID = p.GAME_ID 
GROUP BY 
  g.ID 
ORDER BY 
  COUNT( p.ID ) / g.MAX_NUM_OF_PLAYERS DESC 

它需要大约 4 秒。

解释主要给了我这个:

在此处输入图像描述

如何让它更快?

4

1 回答 1

1

试试这个查询。它更快吗?

select g.*,p.NUM_OF_PLAYERS NUM_OF_PLAYERS 
from games g
left join 
(
select GAME_ID, COUNT( ID ) NUM_OF_PLAYERS 
  from players group by GAME_ID
) p on (g.ID = p.GAME_ID)

ORDER BY 
  p.NUM_OF_PLAYERS/g.MAX_NUM_OF_PLAYERS DESC
于 2013-01-10T14:16:23.463 回答