Amazon SQL Interview: “Finding user purchases”

Find the solution and explanation for an Amazon SQL Interview question.