My accepted solutions


  • 0
    H
    SELECT c.Score, d.Rank FROM Scores AS c
    LEFT JOIN (
    	SELECT Score, @r:=@r+1 AS Rank FROM (
    		SELECT Score FROM Scores AS ins, (SELECT @r:=0) AS A GROUP BY ins.Score ORDER BY ins.Score DESC
    	) AS e
    ) AS d ON c.Score = d.Score
    ORDER BY c.Score DESC
    
    SELECT
    	Score, 
    	@r:=(CASE WHEN last_score = Score THEN @r ELSE @r+1 END) AS Rank
    FROM (
    	SELECT 
    		Score, 
    		@last_score:=@last_score AS last_score,
    		@last_score:=Score
    	FROM Scores, (SELECT @r:=0, @last_score:=NULL) AS A ORDER BY Score DESC
    ) AS B

Log in to reply
 

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