Amazon interview question

Writing a query in SQL