Amazon Interview Question

How would you optimise this sql query?