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.
- Prepare
- SQL
- Basic Join
- Contest Leaderboard
- Discussions
Contest Leaderboard
Contest Leaderboard
Sort by
recency
|
2167 Discussions
|
Please Login in order to post a comment
SELECT h.hacker_id, h.name, t.sumscore FROM Hackers as h JOIN total_score as t ON h.hacker_id = t.hacker_id WHERE t.sumscore > 0 ORDER BY t.sumscore DESC, h.hacker_id ASC
with max_scores as ( select s.hacker_id, h.name, max(s.score) as max_scores from submissions s inner join hackers h on s.hacker_id = h.hacker_id group by s.hacker_id, h.name, s.challenge_id) select hacker_id, name, sum(max_scores) from max_scores group by hacker_id, name having sum(max_scores) > 0 order by 3 desc, 1 asc;
ATTENTION! BUG FOUND! Apparently this particular problem environment isn't supporting CTEs and cites the WITH clause as an 1064 error. Either HackerRank needs to debug this or clarify in the problem description that the intent is to demonstrate achieving the same result without the explicit use of a CTE.
/* MY SQL */
select a.hacker_id ,a.name ,sum(a.score) from ( select h.hacker_id ,h.name ,s.challenge_id ,MAX(s.score) as score from Hackers h join Submissions s on h.hacker_id = s.hacker_id group by h.hacker_id ,h.name ,s.challenge_id ) a
group by a.hacker_id ,a.name
HAVING sum(a.score) > 1
order by sum(a.score) desc , a.hacker_id