Domanda di colloquio di Allstate

How would you solve this problem using SQL