Knowee
Questions
Features
Study Tools

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_id, name, 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 FormatThe following tables contain contest data:Hackers: The hacker_id is the id of the hacker, and name is the name of the hacker. 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. Sample InputHackers Table: Submissions Table: Sample Output4071 Rose 19174842 Lisa 17484072 Bonnie 1004806 Angela 8926071 Frank 8580305 Kimberly 6749438 Patrick 43ExplanationHacker 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 4806, 26071, 80305, and 49438 can be similarly calculated.

Question

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_id, name, 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 FormatThe following tables contain contest data:Hackers: The hacker_id is the id of the hacker, and name is the name of the hacker. 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. Sample InputHackers Table: Submissions Table: Sample Output4071 Rose 19174842 Lisa 17484072 Bonnie 1004806 Angela 8926071 Frank 8580305 Kimberly 6749438 Patrick 43ExplanationHacker 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 4806, 26071, 80305, and 49438 can be similarly calculated.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Based on the problem statement, you are required to write a SQL query. Here is a step-by-step solution:

  1. First, you need to calculate the maximum score for each hacker for each challenge. You can do this using the GROUP BY clause on hacker_id and challenge_id and applying the MAX function on the score column.

  2. Next, you need to calculate the total score for each hacker. You can do this by grouping the result from the first step by hacker_id and summing up the maximum scores.

  3. Then, you need to join the result from the second step with the Hackers table to get the names of the hackers.

  4. Finally, you need to order the result by the total score in descending order and by hacker_id in ascending order. You also need to exclude hackers with a total score of 0.

Here is the SQL query that follows these steps:

SELECT h.hacker_id, h.name, SUM(max_score) as total_score
FROM Hackers h
JOIN (
    SELECT hacker_id, MAX(score) as max_score
    FROM Submissions
    GROUP BY hacker_id, challenge_id
) s ON h.hacker_id = s.hacker_id
GROUP BY h.hacker_id, h.name
HAVING total_score > 0
ORDER BY total_score DESC, h.hacker_id ASC;

This query first calculates the maximum score for each challenge for each hacker, then sums up these scores to get the total score for each hacker. It then joins this with the Hackers table to get the names of the hackers. The HAVING clause is used to exclude hackers with a total score of 0. The result is ordered by the total score in descending order and by hacker_id in ascending order.

This problem has been solved

Similar Questions

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 FormatThe 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 InputHackers Table: Difficulty Table: Challenges Table: Submissions Table: Sample Output

Julia asked her students to create some coding challenges. Write a query to print the hacker_id, name, and the total number of challenges created by each student. Sort your results by the total number of challenges in descending order. If more than one student created the same number of challenges, then sort the result by hacker_id. If more than one student created the same number of challenges and the count is less than the maximum number of challenges created, then exclude those students from the result.Input FormatThe following tables contain challenge data:Hackers: The hacker_id is the id of the hacker, and name is the name of the hacker. Challenges: The challenge_id is the id of the challenge, and hacker_id is the id of the student who created the challenge.

select h.hacker_id,h.name,sum(max(s.score)) from hackers h JOIN submissions s ON h.hacker_id=s.hacker_idgroup by h.hacker_idhaving sum(max(s.score)>0 order by sum(max(s.score) desc,h.hacker_id;

In a coding contest, there are prizes for the top rankers. The prize scheme is as follows:Top 1010 participants receive rupees 𝑋X each.Participants with rank 1111 to 100100 (both inclusive) receive rupees 𝑌Y each.Find the total prize money over all the contestants.Input FormatFirst line will contain 𝑇T, number of test cases. Then the test cases follow.Each test case contains of a single line of input, two integers 𝑋X and 𝑌Y - the prize for top 1010 rankers and the prize for ranks 1111 to 100100 respectively.Output FormatFor each test case, output the total prize money over all the contestants.Constraints1≤𝑇≤10001≤T≤10001≤𝑌≤𝑋≤10001≤Y≤X≤1000Sample 1:InputOutput41000 1001000 100080 1400 30190001000008906700Explanation:Test Case 11: Top 1010 participants receive rupees 10001000 and next 9090 participants receive rupees 100100 each. So, total prize money =10⋅1000+90⋅100=19000=10⋅1000+90⋅100=19000.Test Case 22: Top 1010 participants receive rupees 10001000 and next 9090 participants receive rupees 10001000 each. So, total prize money =10⋅1000+90⋅1000=100000=10⋅1000+90⋅1000=100000.Test Case 33: Top 1010 participants receive rupees 8080 and next 9090 participants receive rupee 11 each. So, total prize money =10⋅80+90⋅1=890=10⋅80+90⋅1=890.Test Case 44: Top 1010 participants receive rupees 400400 and next 9090 participants receive rupees 3030 each. So, total prize money =10⋅400+90⋅30=6700=10⋅400+90⋅30=6700.

You work in the examination department of a school, and you've been given a task to sort the test scores of students in ascending order. The scores are stored in a list where each element represents the score of a student.Input FormatThe first line contains the integer N, the size of the array. The next line contains N space-separated integers.Constraints• 1<=N<=1000 • -1000<=a[i]<=1000Output FormatPrint the array as a row of space-separated integers in each iteration.Sample Input 01010 9 8 7 6 5 4 3 2 1Sample Output 05 9 8 7 6 10 4 3 2 15 4 8 7 6 10 9 3 2 15 4 3 7 6 10 9 8 2 15 4 3 2 6 10 9 8 7 15 4 3 2 1 10 9 8 7 63 4 5 2 1 10 9 8 7 63 2 5 4 1 10 9 8 7 61 2 3 4 5 10 9 8 7 61 2 3 4 5 10 9 8 7 61 2 3 4 5 10 9 8 7 61 2 3 4 5 8 9 10 7 61 2 3 4 5 8 7 10 9 61 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 10

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.