1plusX interview question

How would you create an SQL query for this...