[MSSQL] 해커랭크(HackerRank) - Contest Leaderboard

develop_wan·2022년 1월 3일

HackerRank SQL

목록 보기
50/51
post-thumbnail

https://www.hackerrank.com/challenges/contest-leaderboard/problem?isFullScreen=true


문제


해석
해커의 총점은 모든 과제에 대한 최대 점수의 합계입니다. 내림차순 점수로 정렬된 해커의 hacker_id, 이름 및 총 점수를 출력하기 위한 쿼리를 작성합니다. 둘 이상의 해커가 동일한 총점을 획득한 경우 hacker_id 오름차순으로 결과를 정렬합니다. 총점 0점의 모든 해커를 당신의 결과에서 제외하세요.

select
    h.hacker_id
,   h.name
,   sum(score)
from
    (
    select
        hacker_id
    ,   challenge_id
    ,   max(score) as score
    from
        submissions
    group by
        hacker_id
    ,   challenge_id
    ) as t
    join hackers as h on t.hacker_id = h.hacker_id
group by
    h.hacker_id
,   h.name
having
    sum(score) > 0
order by
    sum(score) desc
,   h.hacker_id
profile
서른. 개발자가 되기로 했다

0개의 댓글