Pregunta de entrevista de Allstate

How would you solve this problem using SQL