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.
The following tables contain contest data:
Hackers Table:
Difficulty Table:
Challenges Table:
Submissions Table:
90411 Joe
Hacker 86870 got a score of 30 for challenge 71055 with a difficulty level of 2, so 86870 earned a full score for this challenge. Hacker 90411 got a score of 30 for challenge 71055 with a difficulty level of 2, so 90411 earned a full score for this challenge. Hacker 90411 got a score of 100 for challenge 66730 with a difficulty level of 6, so 90411 earned a full score for this challenge. Only hacker 90411 managed to earn a full score for more than one challenge, so we print the their hacker_id and name as 2 space-separated values.
select h.hacker_id||' '||name
from hackers h, difficulty d, challenges c, submissions s
where s.hacker_id=h.hacker_id
and s.challenge_id=c.challenge_id
and c.difficulty_level=d.difficulty_level --JOIN
and d.score=s.score
group by h.hacker_id, name
having count(*)>=2
order by count(*) desc, h.hacker_id;
해커가 만점을 얻은 총 챌린지 수에 따라 출력을 내림차순으로 정렬하십시오.
얻은 총 챌린지 수가 기준인데, 챌린지 점수로 order을 해서 결과가 잘못나왔었다.
각각의 테이블을 조인한 후,
group by hacker_id, name
으로 그룹핑을 해서 각 사람이 만점을 받은 수를 계산했다.
글이 잘 정리되어 있네요. 감사합니다.