Saturday Sales by Loyalty Tier
Problem
A farmers' market opens every Saturday. In September 2024 the four Saturdays fell on the 7th, 14th, 21st, and 28th. Using `Orders` (one row per purchase, with the buyer's `shopper_id`, the `order_day`, and the `cents_paid`) and `Shoppers` (each shopper's loyalty `tier`), report the total spend by `Gold` and `Silver` shoppers on each of those four Saturdays. Week 1 is the first Saturday and so on. Every combination of week and the two tiers must appear, with a total of 0 when there were no qualifying purchases. Return `week_no`, `tier`, and `total_cents`, ordered by `week_no` then `tier`.
Tables
Example rows — the live problem includes the full dataset.
| shopper_id | order_day | cents_paid |
|---|---|---|
| 11 | 2024-09-07 | 1126 |
| 15 | 2024-09-14 | 7473 |
| 17 | 2024-09-21 | 2414 |
| shopper_id | tier |
|---|---|
| 11 | Gold |
| 15 | Silver |
| 17 | Bronze |
Expected output
Your answer should return 8 rows with the columns week_no, tier, total_cents.
Starter code (SQL)
SELECT *
FROM Orders;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock