Pergunta de entrevista da empresa OP-Pohjola

How would you write this in SQL