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 temp as
(select
h.hacker_id hid,h.name hname,
count(c.challenge_id) cnt,
count(*) over(PARTITION BY count(c.challenge_id)) as freq
from hackers h
join challenges c on h.hacker_id = c.hacker_id
group by h.hacker_id, h.name)
select hid, hname, cnt
from temp
where freq = 1
or cnt in (select max(temp.cnt) from temp)
order by cnt desc,hid;
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 →
Using a dummy frequency column
with temp as (select h.hacker_id hid,h.name hname, count(c.challenge_id) cnt, count(*) over(PARTITION BY count(c.challenge_id)) as freq from hackers h join challenges c on h.hacker_id = c.hacker_id group by h.hacker_id, h.name) select hid, hname, cnt from temp where freq = 1 or cnt in (select max(temp.cnt) from temp) order by cnt desc,hid;