728x90
문제
Column Name | Type |
id | int |
score | decimal |
id is the primary key (column with unique values) for this table.
Each row of this table contains the score of a game.
Score is a floating point value with two decimal places.
score 별 rank 를 매기고 각 score 별 순위를 score 별 내림차순으로 출력해라.
풀이
SELECT A.score, R.idx as rank FROM Scores A
LEFT OUTER JOIN (SELECT score, ROW_NUMBER() OVER (ORDER BY score DESC) AS idx
FROM Scores group by score) R ON A.score = R.score
order by A.score desc
score 별 내림차순 후 인덱스 열 추가를 통해 순위 열을 생성하고 해당 테이블을 조인하여 출력하였다.
300x250
'Data & BI > SQL Coding Test' 카테고리의 다른 글
[LeetCode](중급) 184. Department Highest Salary 풀이 (6) | 2025.06.13 |
---|---|
[LeetCode](중급) 176. Second Highest Salary (0) | 2025.05.16 |
[LeetCode](초급) 183. Customers Who Never Order (1) | 2025.05.16 |
[LeetCode](초급) 182. Duplicate Emails (0) | 2025.05.16 |
[LeetCode](초급) 175.Combine Two Tables (0) | 2025.05.16 |