Infosys Interview Question

SQL hard problem from Leetcode SQL 50