SQL Grouping and Subquery
Challenge: https://www.hackerrank.com/challenges/contest-leaderboard/problem
Solution by https://www.hackerrank.com/basaks
SQL Grouping and Subquery
Challenge: https://www.hackerrank.com/challenges/contest-leaderboard/problem
Solution by https://www.hackerrank.com/basaks
SQL Grouping and Subquery #1
https://www.hackerrank.com/challenges/full-score/problem
Solution by: https://www.hackerrank.com/ATMaher
| select h.hacker_id, h.name, sum(max_score.score) as total_score | |
| from hackers as h | |
| inner join | |
| /* find max_score per user/challenge */ | |
| (select hacker_id, max(score) as score from submissions group by challenge_id, hacker_id) max_score | |
| on h.hacker_id = max_score.hacker_id | |
| group by h.hacker_id, h.name | |
| -- /* don't accept hackers with total_score=0 */ | |
| having total_score > 0 | |
| -- /* finally order as required */ | |
| order by total_score desc, h.hacker_id; |
| SELECT h.hacker_id, h.name | |
| FROM submissions s | |
| JOIN challenges c | |
| ON s.challenge_id = c.challenge_id | |
| JOIN difficulty d | |
| ON c.difficulty_level = d.difficulty_level | |
| JOIN hackers h | |
| ON s.hacker_id = h.hacker_id | |
| WHERE s.score = d.score | |
| GROUP BY h.hacker_id, h.name | |
| HAVING COUNT(s.hacker_id) > 1 | |
| ORDER BY COUNT(s.hacker_id) DESC, s.hacker_id ASC |