假设您具有以下架构(id,user_id,score)。如何为每个用户提供具有最高分数的行,然后为所有行排序以获得分数。换句话说,我想要一个每个用户都有最佳结果的排名。
答案 0 :(得分:1)
select user_id, max(score)
from user_scores
group by user_id
order by max(score)
答案 1 :(得分:0)
应该是这样的:
SELECT UNIQUE user_id, score FROM TABLE
ORDER BY SCORE DESC
答案 2 :(得分:0)
select @rownum := @rownum + 1 AS rank, user_id, MAX(score) as Score
from table_name t,
(SELECT @rownum := 0) r
GROUP BY user_id
ORDER BY Score