Route interview question

SQL leet code medium level question