Appirio interview question

sql query