새소식

IT/SQL

[해커랭크] Top Competitors

  • -
728x90
반응형

문제링크 : https://www.hackerrank.com/challenges/full-score/problem?isFullScreen=true

 

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. 

Sample Input

Hackers Table: 

 Difficulty Table: 

 Challenges Table: 

 Submissions Table: 

Sample Output

90411 Joe

Explanation

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.


 

🔉 문제 설명

(도와줘요 번역기)

Julia는 방금 코딩 콘테스트 실시를 마쳤고 리더보드를 구성하는 데 도움이 필요합니다! 각각의 hacker_id  둘 이상의 도전 에서 만점을 얻은 해커의 이름을 인쇄하는 쿼리를 작성합니다 . 해커가 만점을 얻은 총 챌린지 수에 따라 출력을 내림차순으로 정렬하십시오. 한 명 이상의 해커가 동일한 수의 도전에서 만점을 받은 경우 hacker_id 를 오름차순으로 정렬합니다 .

 

[설명]

Hacker 86870은 난이도 2 의 챌린지 71055 에서 30 점을 얻었 으므로 86870은 이 챌린지에서 만점을 받았습니다.

Hacker 90411은 난이도 2 의 챌린지 71055 에서 30 점을 얻었 으므로 90411은 이 챌린지에서 만점을 받았습니다.

Hacker 90411은 난이도 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

 


 

 

728x90
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.