OP-Pohjola interview question

How would you write this in SQL