AnalystPath

Total Parcel Weight per Courier

SQLEasyJunior level~15 min

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.

couriers
courier_idcourier_name
1Mia
2Owen
3Ava
deliveries
delivery_idcourier_idweight_kg
11120
22317
33222

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

Related SQL questions