T-SQL Solution to Rank Scores


  • 0
    B

    T-SQL Solution

    
    with cte as(
    SELECT DISTINCT Score, ROW_NUMBER() OVER (ORDER BY Score DESC) as [Rank]
    FROM Scores
    GROUP BY Score)
    
    SELECT s.Score, c.[Rank]
    FROM Scores AS s
    JOIN cte AS c
    ON s.score = c.score
    ORDER BY c.[Rank]
    
    
    

Log in to reply
 

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