Amazon interview question

A complicated query using joins.