Rank Scores using left join


  • 0
    S

    First get all distinct scores with rank added as 'TEMP_TABLE'

    select @ROW:=@ROW+1 Rank, content.Score Score 
    from (select score from Scores group by score order by score desc) content, (select @ROW:=0)
    

    Then use this temp table to do a left join with original content table and setup the Rank for each score.

    select s.Score Score, ro.Rank Rank 
    from Scores s 
    left join (TEMP_TABLE) ro  on ro.score = s.score order by Rank asc
    

Log in to reply
 

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