Amazon interview question

SQL: something like self join, window function