Amazon interview question

How would you optimise this sql query?