Recro interview question

I have been given a medium level coding question and mysql query to solve.