Pregunta de entrevista de OP-Pohjola

How would you write this in SQL