Pergunta de entrevista da empresa SISTIC.com

SQL question related to querying with group by, window functions and CTEs