[해커랭크] Top Competitors

june·2023년 3월 30일
0

SQL

목록 보기
15/31

Top Competitors

https://www.hackerrank.com/challenges

  • Write a query to print the respective hacker_id and name of hackers who achieved full scores for more than one challenge. Order your output in descending order by the total number of challenges in which the hacker earned a full score. If more than one hacker received full scores in same number of challenges, then sort them by ascending hacker_id.
SELECT h.hacker_id
     , h.name
FROM submissions s
    INNER JOIN challenges c ON s.challenge_id = c.challenge_id
    INNER JOIN difficulty d ON c.difficulty_level = d.difficulty_level 
    INNER JOIN hackers h ON s.hacker_id = h.hacker_id
WHERE s.score = d.score
GROUP BY h.hacker_id, h.name
HAVING COUNT(s.hacker_id) > 1
ORDER BY COUNT(s.hacker_id) DESC, s.hacker_id

Lesson & Learned

GROUP BY절에 h.name 을 안넣으면 에러가 발생한다.

profile
나의 계절은

0개의 댓글