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 A as (
select submission_date, A.hacker_id, count(submission_id) n_submit
from Submissions A
group by submission_date, A.hacker_id
)
, B as (
select submission_date, hacker_id, n_submit
, rank () over (partition by submission_date order by n_submit desc) rn
from A
), C as (
select submission_date, count(distinct hacker_id) num_hacker
from Submissions
group by submission_date
)
, D as (select *,
row_number () over (partition by submission_date order by hacker_id) rn2
from B
where rn = 1 )
-- select * from D
select C.submission_date, C.num_hacker, D.hacker_id, E.name
from C
join D on C.submission_date = D.submission_date and rn2 = 1
join Hackers E on D.hacker_id = E.hacker_id
order by submission_date
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
15 Days of Learning SQL
You are viewing a single comment's thread. Return to all comments →
show me any wrong from this solution :
with A as ( select submission_date, A.hacker_id, count(submission_id) n_submit from Submissions A group by submission_date, A.hacker_id ) , B as ( select submission_date, hacker_id, n_submit , rank () over (partition by submission_date order by n_submit desc) rn from A ), C as ( select submission_date, count(distinct hacker_id) num_hacker from Submissions group by submission_date ) , D as (select *, row_number () over (partition by submission_date order by hacker_id) rn2 from B where rn = 1 ) -- select * from D select C.submission_date, C.num_hacker, D.hacker_id, E.name from C join D on C.submission_date = D.submission_date and rn2 = 1 join Hackers E on D.hacker_id = E.hacker_id order by submission_date