Tech Mahindra interview question

Showed SQL query and asked to solve