GEP interview question

SQL query