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
|
2240 Discussions
|
Please Login in order to post a comment
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 ;
sql server
WITH cte1 AS ( SELECT s.hacker_id, h.name, challenge_id, MAX(score) AS max_score FROM submissions s INNER JOIN hackers h ON s.hacker_id = h.hacker_id GROUP BY s.hacker_id, h.name, s.challenge_id HAVING MAX(score) > 0
)
SELECT hacker_id, name, SUM(max_score) AS total_score FROM cte1 GROUP BY hacker_id, name ORDER BY SUM(max_score) DESC, hacker_id ASC;
select newtable.a,newtable.d,sum(newtable.maxscore) from( select hackers.hacker_id as a ,submissions.challenge_ID as b,max(submissions.score) as maxscore,hackers.name as d from hackers join submissions on hackers.hacker_ID=submissions.hacker_id group by hackers.hacker_id,submissions.challenge_id,hackers.name) as newtable group by newtable.a,newtable.d having sum(newtable.maxscore)>0 order by sum(newtable.maxscore) desc ,newtable.a asc