Amazon Interview Question

how do you code this in SQL