-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTop Competitors.sql
More file actions
20 lines (18 loc) · 893 Bytes
/
Top Competitors.sql
File metadata and controls
20 lines (18 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* Julia just finished conducting a coding contest,
and she needs your help assembling the leaderboard!
Write a query to print the respective hacker_id and name of hackers who achieved full scores for more than one challenge.
Order your output in descending order by the total number of challenges in which the hacker earned a full score.
If more than one hacker received full scores in same number of challenges, then sort them by ascending hacker_id. */
--
-- Author: Pavith Bambaravanage
-- URL: https://github.com/Pavith19
--
SELECT h.hacker_id, h.name
FROM submissions s
INNER JOIN challenges c ON s.challenge_id = c.challenge_id
INNER JOIN hackers h ON s.hacker_id = h.hacker_id
INNER JOIN difficulty d ON c.difficulty_level = d.difficulty_level
WHERE s.score = d.score
GROUP BY h.hacker_id, h.name
HAVING COUNT(h.hacker_id) > 1
ORDER BY COUNT(h.hacker_id) DESC, h.hacker_id ASC;