Pregunta de entrevista de Barclays

SQL question on joins, group by, cte.