Pergunta de entrevista da empresa Allstate

How would you solve this problem using SQL