Total Parcel Weight per Courier
Problem
A delivery depot tracks every parcel its couriers carry. Management wants the total weight each courier has delivered, including couriers who have not delivered anything yet.
Table: `couriers`
| Column | Type |
|-------------|---------|
| courier_id | int |
| courier_name| varchar |
`courier_id` is the primary key.
Table: `deliveries`
| Column | Type |
|-------------|---------|
| delivery_id | int |
| courier_id | int |
| weight_kg | int |
`delivery_id` is the primary key. `weight_kg` is the weight of one delivered parcel by the courier.
Write a query that reports, for every courier, the total weight they delivered as `total_weight`. A courier with no deliveries should report `0`. Order the result by `total_weight` descending; when two or more couriers have the same total, order those by `courier_name` ascending.
Tables
Example rows — the live problem includes the full dataset.
| courier_id | courier_name |
|---|---|
| 1 | Mia |
| 2 | Owen |
| 3 | Ava |
| delivery_id | courier_id | weight_kg |
|---|---|---|
| 1 | 1 | 120 |
| 2 | 2 | 317 |
| 3 | 3 | 222 |
Expected output
Your answer should return 7 rows with the columns courier_name, total_weight.
Starter code (SQL)
SELECT *
FROM couriers;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