views:

30

answers:

3

Suppose you have the following schema (id, user_id , score). How can I take per each user the row with max score and then order all row for score. In other word I want a ranking where each user have his best result.

A: 

Should be something like:

 SELECT UNIQUE user_id, score FROM TABLE 
    ORDER BY SCORE DESC
Robert
+1  A: 
select user_id, max(score)
from user_scores
group by user_id
order by max(score)
Tommi
A: 
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
Salil