Contest Leaderboard

  • + 0 comments
    /*
    MSSQL
    */
    with cte as (
    select s.hacker_id, h.name, s.challenge_id, s.score,
        row_number() over(partition by s.hacker_id, s.challenge_id order by s.score desc) as rn
        from submissions s join hackers h
        on s.hacker_id = h.hacker_id
    )
    select hacker_id, name,
        sum(score) as total_score
    from cte
        where rn = 1
        group by hacker_id, name
        having sum(score) > 0
        order by total_score desc, hacker_id asc