Quantiphi Interview Question

Sql queries, puzzle