Domanda di colloquio di Société Générale

Sql query about aggregation and pattern printing question