Find Active Users
You're working for an e-commerce platform that needs to identify active customers for targeted marketing campaigns. An active user is someone who has made multiple purchases within a short time window - specifically, a user who has made a second purchase within 7 days of any other purchase.
Given: A database table Users containing purchase records:
| Column Name | Type |
|---|---|
| user_id | int |
| item | varchar |
| created_at | datetime |
| amount | int |
Goal: Return a list of user_ids who qualify as active users.
Important: "Within 7 days" means inclusive. For example, if one purchase is on May 31, 2023, then any purchase between May 31, 2023 and June 7, 2023 (inclusive) counts as within 7 days.
Example: If a user bought an item on June 1st and another item on June 6th, they're active (5 days apart). If they bought on June 1st and June 8th, they're still active (7 days apart, inclusive).
Input & Output
Constraints
- 1 โค number of records โค 104
- 1 โค user_id โค 103
- created_at is in 'YYYY-MM-DD' format
- 1 โค amount โค 104
- item is a non-empty string with length โค 50