We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
there wasn't necessity of two inner queries.
SELECT Q.hacker_id, Q.name, SUM(Q.Max_score) AS total_score
FROM
(
SELECT h.hacker_id, h.name, s.challenge_id, MAX(s.score) AS Max_score
FROM hackers AS h
INNER JOIN submissions AS s
ON h.hacker_id = s.hacker_id
group by h.hacker_id, h.name, s.challenge_id
) AS Q
group by Q.hacker_id, Q.name
having SUM(Q.Max_score) <> 0
ORDER BY total_score DESC, Q.hacker_id;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Contest Leaderboard
You are viewing a single comment's thread. Return to all comments →
there wasn't necessity of two inner queries. SELECT Q.hacker_id, Q.name, SUM(Q.Max_score) AS total_score FROM ( SELECT h.hacker_id, h.name, s.challenge_id, MAX(s.score) AS Max_score FROM hackers AS h INNER JOIN submissions AS s ON h.hacker_id = s.hacker_id group by h.hacker_id, h.name, s.challenge_id ) AS Q group by Q.hacker_id, Q.name having SUM(Q.Max_score) <> 0 ORDER BY total_score DESC, Q.hacker_id;