🤔 문제 분석
1. You did such a great job helping Julia with her last coding contest challenge that she wants you to work on this one, too!
2. The total score of a hacker is the sum of their maximum scores for all of the challenges.
3. Write a query to print the hacker_id, name, and total score of the hackers ordered by the descending score.
4. If more than one hacker achieved the same total score, then sort the result by ascending hacker_id. Exclude all hackers with a total score of from your result.
💡 풀이
SELECT hacker_id, name, SUM(score) AS score
FROM(
SELECT h.hacker_id, h.name, challenge_id, max(score) AS score
FROM Submissions AS s
INNER JOIN Hackers AS h on s.hacker_id = h.hacker_id
GROUP BY hacker_id, name, challenge_id
) AS sub
GROUP BY hacker_id, name
HAVING score <> 0
ORDER BY score DESC, hacker_id
'코딩테스트 > 해커랭크 SQL' 카테고리의 다른 글
[해커랭크/MSSQL] 40. Ollivander's Inventory (0) | 2023.03.21 |
---|---|
[해커랭크/SQL] 39. Top Competitors (0) | 2023.03.17 |
[해커랭크/SQL] 37. The Report (0) | 2023.03.16 |
[해커랭크/SQL] 36. Weather Observation Station 18 (0) | 2023.03.16 |
[해커랭크/SQL] 35. Binary Tree Nodes (0) | 2023.03.14 |
댓글