I was solving a problem on HackerRank
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.
The code I have written :
With max_score as (
select max(score) as mscore, hacker_id, challenge_id
from submissions
group by hacker_id, challenge_id
)
select h.hacker_id, h.name, sum(ms.mscore)
from hackers h join max_score ms on ms.hacker_id = h.hacker_id
group by h.hacker_id, h.name
having sum(ms.mscore)>0
order by sum(ms.mscore) desc, hacker_id asc;
For this I got the below error:
ERROR 1064 (42000) at line 1:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'maxscore as ( select max(score) as mscore, hacker_id, challenge_id from submissi' at line 1
Your Output (stdout)
~ no response on stdout ~ BlogScoringEnvironmentFAQAbout UsSupportCareersTerms Of ServicePrivacy Policy
Please tell me what is the problem with the code and I cannot understand the error.
Also the code is properly running in MS SQL Server but causing error in MySQL