Friday Purchase III - Problem
You're managing a retail analytics system that needs to track Premium and VIP member spending patterns during Friday shopping events in November 2023.
Given two tables:
- Purchases: Contains user purchase records with
user_id,purchase_date, andamount_spend - Users: Contains user membership information with
user_idandmembership(Standard/Premium/VIP)
Your task is to calculate the total spending by Premium and VIP members on each Friday of every week in November 2023. The challenge is to ensure that:
- Only Friday purchases are considered
- Only Premium and VIP members are included (ignore Standard members)
- If no purchases occurred on a Friday by a membership type, show 0
- Results are grouped by week of the month and membership type
This type of analysis helps businesses understand high-value customer behavior during peak shopping days and optimize their Friday marketing campaigns.
Input & Output
example_1.sql โ Basic Friday Analysis
$
Input:
Purchases: [(11,'2023-11-03',1126), (15,'2023-11-10',7473), (17,'2023-11-17',2414), (12,'2023-11-24',9692)]
Users: [(11,'Premium'), (15,'VIP'), (17,'Standard'), (12,'VIP')]
โบ
Output:
[(1,'Premium',1126), (1,'VIP',0), (2,'Premium',0), (2,'VIP',7473), (3,'Premium',0), (3,'VIP',0), (4,'Premium',0), (4,'VIP',9692)]
๐ก Note:
Nov 3rd (Week 1): Premium member spent $1126, no VIP purchases. Nov 10th (Week 2): VIP member spent $7473, no Premium purchases. Nov 17th (Week 3): Only Standard member purchased (ignored). Nov 24th (Week 4): VIP member spent $9692.
example_2.sql โ Multiple Same-Day Purchases
$
Input:
Purchases: [(8,'2023-11-24',5117), (1,'2023-11-24',5241), (12,'2023-11-24',9692)]
Users: [(8,'Premium'), (1,'VIP'), (12,'VIP')]
โบ
Output:
[(1,'Premium',0), (1,'VIP',0), (2,'Premium',0), (2,'VIP',0), (3,'Premium',0), (3,'VIP',0), (4,'Premium',5117), (4,'VIP',14933)]
๐ก Note:
All purchases on Nov 24th (Week 4): Premium member spent $5117, two VIP members spent $5241 + $9692 = $14933 total. All other weeks show 0 for both membership types.
example_3.sql โ No Premium/VIP Friday Purchases
$
Input:
Purchases: [(17,'2023-11-03',1000), (10,'2023-11-10',2000), (13,'2023-11-17',3000)]
Users: [(17,'Standard'), (10,'Standard'), (13,'Standard')]
โบ
Output:
[(1,'Premium',0), (1,'VIP',0), (2,'Premium',0), (2,'VIP',0), (3,'Premium',0), (3,'VIP',0), (4,'Premium',0), (4,'VIP',0)]
๐ก Note:
All purchases were made by Standard members, which are filtered out. Result shows 0 for all Premium/VIP combinations across all weeks, demonstrating proper handling of missing data.
Constraints
- purchase_date ranges from November 1, 2023, to November 30, 2023 inclusive
- membership is ENUM type with values ('Standard', 'Premium', 'VIP')
- 1 โค user_id โค 1000
- 1 โค amount_spend โค 105
- Only Friday purchases by Premium/VIP members should be included
- Results must be ordered by week_of_month and membership in ascending order
Visualization
Tap to expand
Understanding the Visualization
1
Identify Target Days
Find all Fridays in November 2023 (3rd, 10th, 17th, 24th)
2
Filter Premium Customers
Focus only on Premium and VIP membership levels
3
Group by Week & Membership
Aggregate spending for each Friday by membership type
4
Fill Missing Data
Show 0 for weeks/memberships with no Friday purchases
Key Takeaway
๐ฏ Key Insight: Use SQL's date functions and JOINs to efficiently filter, aggregate, and handle missing data in a single query rather than multiple manual operations.
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code