Notice
Recent Posts
Recent Comments
Link
복's
[ LeetCode - 178 ] Rank Scores 본문
728x90
https://leetcode.com/problems/rank-scores/description/
Rank Scores - LeetCode
Can you solve this real interview question? Rank Scores - Table: Scores +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | score | decimal | +-------------+---------+ id is the primary key (column with unique values)
leetcode.com
음... 진짜 rank 함수만 쓰면 바로 넘어갈 수 있는 문제였다.
습관적으로 맨 처음에는 서브 쿼리를 썼지만 사실 랭킹이랑 점수만 출력하면 되는거지 조건이 따로 필요 없어서 그냥 select 해주기만 하면 된다.
[ 📌 풀이 ]
풀이랄것도 없지만 딱 하나 공동 랭킹을 허용 하면서 공동 랭킹시 다음 랭크는 공통 랭킹 다음 랭킹으로 변하는것만 신경쓰면 된다.
ex)
4.0 -> 1등 4.0 -> 1등
4.0 -> 1등 4.0 -> 1등
3.5 -> 2등 3.5 -> 3등
랭크 함수 구분만 해주면 될 듯
[ 📌 코드 - Oracle ]
-- Author : Lee In Bok
-- Date : 2023.11.20(Mon)
-- Spend Time: 04m 23s
-- Runtime : 1075 ms (Beats 12.39%)
-- Algoritm : rank
select score
, dense_rank() over(order by score desc) as rank
from Scores
;
[ 📌 결과 - Oracle ]
728x90
'알고리즘 > LeetCode' 카테고리의 다른 글
[ LeetCode - 1189 ] Maximum Number of Balloons (1) | 2023.11.26 |
---|---|
[ LeetCode - 180 ] Consecutive Numbers (0) | 2023.11.25 |
[ LeetCode - 176 ] Second Highest Salary (1) | 2023.11.18 |
[ LeetCode - 100 ] Same Tree (1) | 2023.11.14 |
[ LeetCode - 181 ] Employees Earning More Than Their Managers (0) | 2023.11.12 |