178. Rank Scores

  • 0

    1.Firstly, get distinct scores order by score.
    2.Generate row number as Rank for above ordered distinct scores.
    3.join the score table with score

    select s.Score, b.Rank from Scores s, (select round(@rownum:=@rownum+1) AS Rank, a.Score
    FROM (SELECT @rownum:=0) r, (select distinct Score from Scores order by Score desc) a) b
    where s.Score = b.Score order by s.Score desc

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.