1169ms solution without variables and union

  • 5
      (SELECT COUNT(DISTINCT s1.`Score`) FROM `Scores` s1 WHERE s1.`Score` >= s2.`Score`)
        FROM `Scores` s2
          ORDER BY s2.`Score` DESC

    p.s. please share more faster solutions!

  • 0

    My solutions is not very good, I think, but it exactly runs faster in 940ms. Hoping it can help you and want any comments.

    # Write your MySQL query statement below
    SELECT main.Score, c.Rank
    FROM Scores main, (
        SELECT b.Score AS Score, SUM(a.Score > b.Score) + 1 AS Rank
        FROM (
            SELECT DISTINCT Score
            FROM Scores
            ) AS a,
            SELECT DISTINCT Score
            FROM Scores
            ) AS b
        GROUP BY b.Score
        ) AS c
    WHERE main.Score = c.Score
    ORDER BY main.Score

Log in to reply

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