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.
Awesome. The subquery version works, but I like your version with better performance
select h.hacker_id, h.name, tmp.challenges_created
from Hackers h,
(select hacker_id, count(challenge_id) challenges_created
from Challenges
group by hacker_id
) tmp
where tmp.hacker_id = h.hacker_id
and not exists
(select 'x'
from (select hacker_id, count(challenge_id) challenges_created
from Challenges
group by hacker_id
) tmp2
where tmp2.hacker_id != tmp.hacker_id
and tmp2.challenges_created = tmp.challenges_created
and tmp2.challenges_created <
(select count(challenge_id)
from Challenges
group by hacker_id
order by count(challenge_id) desc
limit 1
)
)
order by challenges_created desc, hacker_id;
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 →
Awesome. The subquery version works, but I like your version with better performance
select h.hacker_id, h.name, tmp.challenges_created from Hackers h, (select hacker_id, count(challenge_id) challenges_created from Challenges group by hacker_id ) tmp where tmp.hacker_id = h.hacker_id and not exists (select 'x' from (select hacker_id, count(challenge_id) challenges_created from Challenges group by hacker_id ) tmp2 where tmp2.hacker_id != tmp.hacker_id and tmp2.challenges_created = tmp.challenges_created and tmp2.challenges_created < (select count(challenge_id) from Challenges group by hacker_id order by count(challenge_id) desc limit 1 ) ) order by challenges_created desc, hacker_id;