Daily Distinct Buyers and Couriers
Problem
Table: `parcel_log`
| Column Name | Type |
|---|---|
| ship_date | date |
| hub_code | varchar |
| buyer_id | int |
| courier_id | int |
This table has no primary key and may contain duplicate rows. Each row records that a parcel was shipped on `ship_date` from warehouse hub `hub_code` for buyer `buyer_id` using courier `courier_id`.
For each combination of `ship_date` and `hub_code`, report the number of **distinct** buyers and the number of **distinct** couriers. Alias the counts `distinct_buyers` and `distinct_couriers`.
Tables
Example rows — the live problem includes the full dataset.
| ship_date | hub_code | buyer_id | courier_id |
|---|---|---|---|
| 2026-01-01 | north | 7 | 3 |
| 2026-01-01 | north | 7 | 4 |
| 2026-01-01 | north | 8 | 3 |
Expected output
Your answer should return 3 rows with the columns ship_date, hub_code, distinct_buyers, distinct_couriers.
Starter code (SQL)
SELECT *
FROM parcel_log;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