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;
Question
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;
Solution
It seems like you're trying to write a SQL query to select the hacker_id and name from the hackers table and the sum of the maximum score from the submissions table for each hacker. However, there are a few syntax errors in your query. Here's a corrected version:
SELECT
h.hacker_id,
h.name,
SUM(s.max_score)
FROM
hackers h
JOIN
(SELECT
hacker_id,
MAX(score) as max_score
FROM
submissions
GROUP BY
hacker_id) s
ON
h.hacker_id = s.hacker_id
GROUP BY
h.hacker_id, h.name
HAVING
SUM(s.max_score) > 0
ORDER BY
SUM(s.max_score) DESC, h.hacker_id;
Here's a step-by-step explanation:
-
The subquery
(SELECT hacker_id, MAX(score) as max_score FROM submissions GROUP BY hacker_id)is used to get the maximum score for each hacker from thesubmissionstable. -
This subquery is then joined with the
hackerstable onhacker_id. -
The
SELECTstatement then selects thehacker_idandnamefrom thehackerstable, and the sum of the maximum scores from the subquery. -
The
GROUP BYclause groups the results byhacker_idandname. -
The
HAVINGclause filters out the hackers whose sum of maximum scores is not greater than 0. -
Finally, the
ORDER BYclause sorts the results in descending order by the sum of maximum scores, and then byhacker_idin case of ties.
Similar Questions
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.
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 the correct answerConsider the following SQL query: SELECT customer_id, MAX(total_amount) AS max_amount FROM Orders GROUP BY customer_id HAVING COUNT(*) > 1;What will be the output of this query?OptionsThe customer IDs and the average order amount for customers who have placed more than one order.The customer IDs and the maximum order amount for customers who have placed more than one order.An error because the HAVING clause is used without an aggregate function in the SELECT clause. An error because the GROUP BY clause is not properly used.
Select the correct answerConsider the following SQL query: SELECT customer_id, MAX(total_amount) AS max_amount FROM Orders GROUP BY customer_id HAVING COUNT(*) > 1;What will be the output of this query?OptionsThe customer IDs and the maximum order amount for customers who have placed more than one order.An error because the HAVING clause is used without an aggregate function in the SELECT clause. An error because the GROUP BY clause is not properly used.The customer IDs and the average order amount for customers who have placed more than one order.
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.