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.
with cte_1 as
(select
c.hacker_id,h.name,count(c.challenge_id) as cnt
from challenges as c
inner join hackers as h on c.hacker_id = h.hacker_id
group by c.hacker_id,h.name
order by cnt desc, c.hacker_id),
cte_2 as (
select
cnt,count(cnt) as count_count from cte_1
group by cnt
having count_count = 1 or cnt = (select max(cnt) from cte_1)
order by cnt desc)
select
cte_1.hacker_id,
cte_1.name,
cte_1.cnt
from
cte_1 inner join cte_2 on cte_1.cnt = cte_2.cnt
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Challenges
You are viewing a single comment's thread. Return to all comments →
Easy to understand :
with cte_1 as (select c.hacker_id,h.name,count(c.challenge_id) as cnt from challenges as c inner join hackers as h on c.hacker_id = h.hacker_id group by c.hacker_id,h.name order by cnt desc, c.hacker_id), cte_2 as ( select cnt,count(cnt) as count_count from cte_1 group by cnt having count_count = 1 or cnt = (select max(cnt) from cte_1) order by cnt desc)
select cte_1.hacker_id, cte_1.name, cte_1.cnt from cte_1 inner join cte_2 on cte_1.cnt = cte_2.cnt