GROUP BY a categorical column with COUNT(*), sorted by count descending
I want the full status breakdown for `fact_shipments`. Group by `status`, count rows per group, label the count `shipment_count`, and sort largest to smallest. Should be three rows.
| 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.
Use GROUP BY status to partition rows by status value.
COUNT(*) inside the SELECT counts rows per group.
ORDER BY shipment_count DESC puts the largest group first.