Skip to content

Instantly share code, notes, and snippets.

@steklopod
Created July 20, 2020 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steklopod/5fc01845fe87b9f9fc8865a5b7c30e2d to your computer and use it in GitHub Desktop.
Save steklopod/5fc01845fe87b9f9fc8865a5b7c30e2d to your computer and use it in GitHub Desktop.
select h.id as hacker_id, name, sum(m_score) as total_score from(
  select h.id, h.name, nvl(max(s.score),0) m_score from hackers h
    left join submissions s on
       s.hacker_id=h.id
    group by h.id, s.challenge_id
)
where m_score > 0
order by total_score desc, name asc;
Hackers (ID, name)
		  1 Иван
		  2 Мария

Submissions (ID, hacker_id, challange_id, score)
            1    1           2            91
            2    1           3            73
            3    1           3            86
            4    2           1            50
            5    2           4            60

Total_score участника равна сумме максимумов для каждой задачи (91 + 86)

  • Вывести hacker_id, name и total_score всех участников, отсортировав записи по total_score в порядке убывания.
  • Если несколько участников набрали одинаковое количество очков, то отсортировать их по name в порядке возрастания.
  • Требуется исключить всех участников с total_score равным нулю.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment