Contest Leaderboard SQL Hacker Rank Solution

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

Contest Leaderboard SQL Hacker Rank Solution
Contest Leaderboard SQL Hacker Rank Solution

Problem

You did such a great job helping Julia with her last coding contest challenge that she wants you to work on this one, too!

The total score of a hacker is the sum of their maximum scores for all of the challenges. Write a query to print the hacker_idname, and total score of the hackers ordered by the descending score. If more than one hacker achieved the same total score, then sort the result by ascending hacker_id. Exclude all hackers with a total score of  from your result.

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. Contest Leaderboard 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 for which the submission belongs to, and score is the score of the submission. Contest Leaderboard SQL Hacker Rank Solution

Sample Input

Hackers Table: Contest Leaderboard SQL Hacker Rank Solution

Submissions Table: Contest Leaderboard SQL Hacker Rank Solution

Sample Output

4071 Rose 191
74842 Lisa 174
84072 Bonnie 100
4806 Angela 89
26071 Frank 85
80305 Kimberly 67
49438 Patrick 43

Explanation

Hacker 4071 submitted solutions for challenges 19797 and 49593, so the total score .

Hacker 74842 submitted solutions for challenges 19797 and 63132, so the total score 

Hacker 84072 submitted solutions for challenges 49593 and 63132, so the total score .

The total scores for hackers 48062607180305, and 49438 can be similarly calculated.

Contest Leaderboard SQL Hacker Rank Solution

SELECT X.hacker_id,
(SELECT H.NAME FROM HACKERS H
                      WHERE H.HACKER_ID = X.HACKER_ID) NAME,
SUM(X.SCORE) TOTAL_SCORE FROM
  (SELECT HACKER_ID, MAX(SCORE) SCORE FROM SUBMISSIONS S
   GROUP BY 1, S.CHALLENGE_ID) X
GROUP BY 1
HAVING TOTAL_SCORE > 0
ORDER BY TOTAL_SCORE DESC, HACKER_ID;

Disclaimer: The above Problem (Contest Leaderboard) 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