Deloitte interview question

Sql data aggregation question on hackerrank