Ascend Group interview question

SQL Query, Database Tool, Logic