coding/sql 코딩테스트

[해커랭크] Contest Leaderboard

임이레 2025. 5. 29. 22:22

 

medium 난이도의 문제 

 

문제에서 원하는 바는 challenge 별 최고 값의 합을 hacker_id 기준으로 나타내는 것이다. 

1. 먼저 hacker_id , challenge_id 기준으로 max(score) 값을 구하여 챌린지별 최상위 스코어를 구함. 

2. 1번을 서브쿼리화 하여 최종적인 답을 구하면 된다. 

select hacker_id 
    , name 
    , sum(max_score) as total_score
from ( 
    SELECT h.hacker_id as hacker_id 
            , h.name as name 
            , s.challenge_id as challenge_id 
            , max(score) as max_score 
    FROM Hackers h join Submissions s on h.hacker_id = s.hacker_id 
group by 1,2,3
) as sub_t 

group by 1,2 
having total_score != 0 
order by total_score DESC , hacker_id ASC

 

 

쿼리 문제를 지속적으로 디벨롭해야 감을 잃지 않는것 같다!