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
|
2243 Discussions
|
Please Login in order to post a comment
WITH filter AS ( SELECT *, ROW_NUMBER() OVER (PARTITION BY hacker_id, challenge_id ORDER BY score DESC) AS rn FROM submissions ) SELECT h.hacker_id, h.name, SUM(f.score) FROM Hackers h JOIN filter f ON h.hacker_id = f.hacker_id WHERE f.rn = 1 GROUP BY h.hacker_id, h.name HAVING SUM(f.score) > 0 ORDER BY SUM(f.score) DESC, h.hacker_id ;
WITH Max_Scores AS ( SELECT hacker_id, challenge_id, MAX(score) AS max_score FROM Submissions GROUP BY hacker_id, challenge_id ), Total_Scores AS ( SELECT hacker_id, SUM(max_score) AS total_score FROM Max_Scores GROUP BY hacker_id ) SELECT h.hacker_id, h.name, ts.total_score FROM Total_Scores ts JOIN Hackers h ON ts.hacker_id = h.hacker_id WHERE ts.total_score > 0 ORDER BY ts.total_score DESC, h.hacker_id;
Using Oracle:
/* Enter your query here. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. */
select * from ( select hacker_id, name, sum(max_score) as total_score from ( select s.hacker_id, h.name, s.challenge_id , max(s.score) as max_score from submissions s join hackers h on s.hacker_id = h.hacker_id group by s.hacker_id, h.name, s.challenge_id --HAVING MAX(S.SCORE)>0 ) group by hacker_id, name ) WHERE TOTAL_SCORE <>0 order by total_score desc, hacker_id asc ;