178 Rank Scores

  • 0
    # Write your MySQL query statement below
    SET @prev_value = NULL;
    SET @rank_count = 0;
    SELECT Id, Score, CASE
        WHEN @prev_value = Score THEN @rank_count
        WHEN @prev_value := Score THEN @rank_count := @rank_count + 1
    END AS rank
    FROM Scores
    ORDER BY Score;

Log in to reply

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