Pergunta de entrevista da empresa 1plusX

How would you create an SQL query for this...