AnalystPath

Saturday Sales by Loyalty Tier

SQLMediumMid level~15 min

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.

Orders
shopper_idorder_daycents_paid
112024-09-071126
152024-09-147473
172024-09-212414
Shoppers
shopper_idtier
11Gold
15Silver
17Bronze

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

Related SQL questions