Top Competitors SQL Hacker Rank Solution

Hello coders, In this post, you will learn how to solve the Top Competitors SQL Hacker Rank Solution. This problem is a part of the SQL Hacker Rank series.

Top Competitors SQL Hacker Rank Solution
Top Competitors SQL Hacker Rank Solution

Top Competitors SQL Hacker Rank Solution

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.
  •  Top Competitors SQL Hacker Rank Solution
  • Difficulty: The difficult_level is the level of difficulty of the challenge, and score is the score of the challenge for the difficulty level.
  •  Top Competitors SQL Hacker Rank Solution
  • 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. Top Competitors SQL Hacker Rank Solution
  • 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.
  •  Top Competitors SQL Hacker Rank Solution

Sample Input

Hackers Table: Top Competitors SQL Hacker Rank Solution Difficulty Table: Top Competitors SQL Hacker Rank Solution Challenges Table: Top Competitors SQL Hacker Rank Solution Submissions Table: Top Competitors SQL Hacker Rank Solution

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  space-separated values.

Top Competitors SQL Hacker Rank Solution

select Hackers.hacker_id, Hackers.name from Hackers
join Submissions
on Hackers.hacker_id = submissions.hacker_id
join Challenges
on Challenges.challenge_id = Submissions.challenge_id
join Difficulty
on Difficulty.difficulty_level = Challenges.difficulty_level
where Submissions.score = Difficulty.score
group by Hackers.hacker_id,Hackers.name having count(*)>1
order by count(*) DESC,Hackers.hacker_id;
30 July 2020 at 02:10

Disclaimer: The above Problem (Top Competitors) generated by Hackerrank but the Solution is Provided by Chase2Learn. This tutorial is only for Educational and Learning purposes.

Sharing Is Caring

Leave a Comment