Julia just finished conducting a coding contest, and she needs your help assembling the leaderboard! Write a query to print the respectivehacker_idandnameof hackers who achieved full scores formore than onechallenge. 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 ascendinghacker_id.
Input Format
The following tables contain contest data:
Hackers:Thehacker_idis the id of the hacker, andnameis the name of the hacker.
Difficulty:Thedifficult_levelis the level of difficulty of the challenge, andscoreis the score of the challenge for the difficulty level.
Challenges:Thechallenge_idis the id of the challenge, thehacker_idis the id of the hacker who created the challenge, anddifficulty_levelis the level of difficulty of the challenge.
Submissions:Thesubmission_idis the id of the submission,hacker_idis the id of the hacker who made the submission,challenge_idis the id of the challenge that the submission belongs to, andscoreis the score of the submission.
Sample Input
HackersTable:
DifficultyTable:
ChallengesTable:
SubmissionsTable:
Sample Output
90411 Joe
Explanation
Hacker86870got a score of30for challenge71055with a difficulty level of2, so86870earned a full score for this challenge.
Hacker90411got a score of30for challenge71055with a difficulty level of2, so90411earned a full score for this challenge.
Hacker90411got a score of100for challenge66730with a difficulty level of6, so90411earned a full score for this challenge.
Only hacker90411managed to earn a full score for more than one challenge, so we print the theirhacker_idandnameas 2space-separated values.
🔉 문제 설명
(도와줘요 번역기)
Julia는 방금 코딩 콘테스트 실시를 마쳤고 리더보드를 구성하는 데 도움이 필요합니다!각각의hacker_id와둘 이상의도전 에서 만점을 얻은 해커의이름을인쇄하는 쿼리를 작성합니다 .해커가 만점을 얻은 총 챌린지 수에 따라 출력을 내림차순으로 정렬하십시오.한 명 이상의 해커가 동일한 수의 도전에서 만점을 받은 경우hacker_id를 오름차순으로 정렬합니다 .
[설명]
Hacker86870은난이도2의 챌린지71055 에서30점을 얻었으므로86870은이 챌린지에서 만점을 받았습니다.
Hacker90411은난이도2의 챌린지71055 에서30점을 얻었으므로90411은이 챌린지에서 만점을 받았습니다.
Hacker90411은난이도6의 챌린지66730 에서100점을 얻었으므로90411은이 챌린지에서 만점을 받았습니다.
해커 90411만이하나 이상의 챌린지에서 만점을 얻었으므로 그들의hacker_id와이름을다음과 같이 인쇄합니다.
2공백으로 구분된 값.
❗답
SELECT s.hacker_id, h.name
FROM Hackers h join Challenges c using(hacker_id)
join Difficulty d using(difficulty_level)
join Submissions s using(score)
WHERE d.score = s.score
GROUP BY s.hacker_id, h.name
HAVING count(s.challenge_id) > 1
ORDER BY count(s.challenge_id) DESC, s.hacker_id