Find delivery exceptions
Count undelivered shipments past their promised date, by warehouse.
Sample schema
shipments(id, warehouse_id, promised_at, delivered_at)
SELECT warehouse_id, COUNT(*) AS overdue_shipments
FROM shipments
WHERE delivered_at IS NULL
AND promised_at < CURRENT_TIMESTAMP
GROUP BY warehouse_id
ORDER BY overdue_shipments DESC;
This measures the current overdue backlog, not all shipments that were ever late. Align promised_at with your timezone and exclude cancelled shipments if your schema records them separately.