Amazon interview question

how do you code this in SQL