178.rank scores


  • 0
    Z
    SELECT
    	t1.score,
    	t1.num
    FROM
    	(
    		SELECT
    			s.score ,@number :=@number + 1 AS num
    		FROM
    			(
    				SELECT
    					score
    				FROM
    					scores
    				GROUP BY
    					score
    				ORDER BY
    					score DESC
    			) AS s,
    			(SELECT @number := 0) AS t
    	) AS t1
    LEFT JOIN scores AS so ON t1.score = so.score
    ORDER BY
    	t1.score DESC
    

Log in to reply
 

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