Intellect Design Arena interview question

Based on Java and SQL with code given to be solved