GlobalLogic interview question

SQL Query