cs

https://www.hackerrank.com/challenges/full-score/problem?isFullScreen=true&h_r=next-challenge&h_v=zen 

 

Top Competitors | HackerRank

Query a list of top-scoring hackers.

www.hackerrank.com

 

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

Hacker Table
Submission Table
Difficulty Table
Challenges 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.

 

 


[My Answer]

SELECT 
    B.hacker_id, B.name 
FROM Submissions A 
    left join Hackers B
        on A.hacker_id = B.hacker_id 
    left join Challenges C
        on A.challenge_id = C.challenge_id
    left join Difficulty D 
        on C.Difficulty_level = D.Difficulty_level
WHERE A.score = D.score 
GROUP BY B.hacker_id, B.name 
HAVING count(*) > 1
ORDER BY count(*) desc, B.hacker_id;

-> 처음에는 뭔가 길어서 되게 복잡한가 싶었는데 사실 조인만 잘 걸면 되는거였고, key값만 잘 찾으면 되는거였다ㅏ. 

조인이 많아져서 그른가 다른 때 보다 실행속도가 느린 느낌이였다..

 

'Code Problems > SQL_ HackerRank' 카테고리의 다른 글

[Hacker Rank] Ollivander's Inventory  (0) 2022.02.24
[Hacker Rank] The Report  (0) 2022.02.06
[Hacker Rank] Symmetric Pairs  (0) 2022.01.24
[Hacker Rank] Placement  (0) 2022.01.24
[HackerRank] Average Population of Each Continent  (0) 2022.01.04

+ Recent posts