Quantiphi interview question

Related to SQL, one coding question, oops, logical aptitude question