www.hackerrank.com/challenges/full-score/problem
Julia just finished conducting a coding contest, and she needs your help assembling the leaderboard! 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.
Input Format
The following tables contain contest data:
-
Hackers: The hacker_id is the id of the hacker, and name is the name of the hacker.
-
Difficulty: The difficult_level is the level of difficulty of the challenge, and score is the score of the challenge for the difficulty level.
-
Challenges: The challenge_id is the id of the challenge, the hacker_id is the id of the hacker who created the challenge, and difficulty_level is the level of difficulty of the challenge.
-
Submissions: The submission_id is the id of the submission, hacker_id is the id of the hacker who made the submission, challenge_id is the id of the challenge that the submission belongs to, and score is the score of the submission.
Answer
select h.hacker_id, h.name # respective hacker_id and name of hackers
from submissions as s
join
hackers as h
on s.hacker_id = h.hacker_id
join
challenges as c
on s.challenge_id = c.challenge_id
join
difficulty as d
on c.difficulty_level = d.difficulty_level
where s.score = d.score
group by h.hacker_id, h.name
having count(*)>1 # who achieved full scores for more than one challenge
order by count(*) desc, h.hacker_id;
Result
'SQL & DB > HackerRank SQL Problem' 카테고리의 다른 글
[HackerRank SQL] Challenges (0) | 2021.03.01 |
---|---|
[HackerRank SQL] Ollivander's Inventory (0) | 2021.03.01 |
[HackerRank SQL] The Report (0) | 2021.03.01 |
[HackerRank SQL] Weather Observation Station 19, 20(MySQL) (0) | 2021.03.01 |
[HackerRank SQL] Weather Observation Station 17, 18(MySQL) (0) | 2021.03.01 |