mysql - 我的 MySQL 查询如何给出所有游戏的排名只给出每个玩家顶级游戏的排名?

标签 mysql ranking rank

SELECT 
1+(SELECT count(*) from games a WHERE a.score > g.score) as rank,
score, p.leaderboard_initials, p.operating_system
FROM games g
inner join players p on (p.google_id = g.google_id)
ORDER BY score DESC
LIMIT 0, 100;

返回一个排行榜,其中包含玩家的每场比赛。

enter image description here

我需要返回一个排行榜,其中只列出了每个玩家的最佳得分游戏。所以 44rhh 仍将排在首位,其次是 DMC,但 BMO 将排在第三位。

我知道解决方案应该很简单,但我就是想不出该怎么做!

最佳答案

您可以按 leaderboard_initials 选择最高分组

您可以按 leaderboard_initials 选择最高分组

set @rank=0;
select (@rank:=@rank+1) rank , leaderboard_initials, max(score)  max_score  
from  (
    SELECT 
    1+(SELECT count(*) 
    from games a WHERE a.score > g.score) as rank,
    score, p.leaderboard_initials, p.operating_system
    FROM games g
    inner join players p on (p.google_id = g.google_id)
    ORDER BY score DESC
    LIMIT 0, 100;
) t  
group by leaderboard_initials 
order by max_score DESC 

关于mysql - 我的 MySQL 查询如何给出所有游戏的排名只给出每个玩家顶级游戏的排名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55381562/

相关文章:

MySQL 使用虚拟列作为连接点?

Mysql 查询获取最近 8 天的数据

php - 使用 PHP、Ajax 和 Jquery 更改密码

mysql - 我如何构建我的数据库以在 MySQL 中有效地按依赖于时间的函数进行排序?

mysql - 在过程中加入 2 个字符串作为查询

machine-learning - SVM 排序查询级特征

php - MySQL:查询有领带的排行榜

python - 排名聚合: Merge local subrankings into global ranking

sql输出作为排名

python - 按 Python 中的计数对多个列表的元素进行排名