Compute a derived column, sort descending, and use LIMIT to return top-N
I need the 5 most expensive shipments by total cost. Compute `total_cost` as freight_cost + fuel_surcharge + accessorial_cost. Return `shipment_id`, `carrier_id`, `lane_id`, `status`, and `total_cost`. Sort by total_cost descending, limit to 5.
| Column | Type | Key |
|---|---|---|
| shipment_id | INT | PK |
| carrier_id | INT | FK → dim_carriers |
| lane_id | INT | FK → dim_lanes |
| planned_pickup_date | TEXT | |
| actual_pickup_date | TEXT | |
| planned_delivery_date | TEXT | |
| actual_delivery_date | TEXT | |
| qty_ordered | INT | |
| qty_shipped | INT | |
| weight_lbs | REAL | |
| freight_cost | REAL | |
| fuel_surcharge | REAL | |
| accessorial_cost | REAL | |
| dwell_hours_at_origin | REAL | |
| status | TEXT |
Each hint you reveal reduces the XP you can earn. Try the query first.
Compute the derived column: freight_cost + fuel_surcharge + accessorial_cost AS total_cost.
Sort by total_cost DESC to bring the most expensive rows to the top.
LIMIT 5 caps the result at five rows.