Mr. John interview question

Puzzle , Programing Questions , Date structure and Algorithms, MySql