Imagine you're working as a data analyst for a major e-commerce platform, and the marketing team wants to identify frequent shoppers to target with special loyalty programs. Your task is to find users who show consistent purchasing behavior by making at least two purchases within a 7-day window.
Given a Purchases table with purchase records, you need to identify all users who made any two purchases at most 7 days apart. This could help the business understand customer buying patterns and reward loyal customers.
Table: Purchases
+---------------+------+ | Column Name | Type | +---------------+------+ | purchase_id | int | | user_id | int | | purchase_date | date | +---------------+------+
Where purchase_id contains unique values, and each row represents a purchase made by a user on a specific date.
Goal: Return the user_ids of all users who made any two purchases with at most 7 days between them, ordered by user_id.
Input & Output
Constraints
- 1 โค Number of purchases โค 105
- 1 โค user_id โค 104
- purchase_date is a valid date between 2020-01-01 and 2024-12-31
- All purchase_id values are unique
- A user can have multiple purchases on the same date