Operative interview question

CPP- 2 CODING QUESTION 2 sql query