Link bài đây ạ: Top Competitors | HackerRank
With Joined as(Select s.hacker_id, s.score as _score, difficulty_level, s.challenge_id
from Submissions s INNER JOIN Challenges ch ON s.challenge_id = ch.challenge_id),
Joined_2 as (Select j.hacker_id, COUNT(DISTINCT j.challenge_id) as cnt from Joined j
INNER JOIN Difficulty d ON j.difficulty_level = d.difficulty_level AND _score = score group by hacker_Id)
Select h.hacker_id, name from Joined_2 j INNER JOIN Hackers h ON j.hacker_id = h.hacker_id order by cnt desc, hacker_id asc;