My solution! No dummy variables.


  • 0
    S
    SELECT Scores.Score AS Score, IFNULL(q3.Rank, 0)+1 AS Rank
        FROM Scores
        LEFT JOIN 
             (SELECT q1.Score AS Score, COUNT(*) AS Rank
                FROM (SELECT DISTINCT Scores.Score AS Score
                        FROM Scores
                        ORDER BY Score DESC) AS q1
                JOIN
                     (SELECT DISTINCT Scores.Score AS Score
                        FROM Scores
                        ORDER BY Score DESC) AS q2
                ON q1.Score < q2.Score
                GROUP BY Score
                ORDER BY Score DESC) AS q3
        ON q3.Score = Scores.Score
        ORDER BY Score DESC
    

    Run time is 841 ms.


Log in to reply
 

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