For rated orders, compare the delivery rating when the delivery was on time with when it was late (on time = delivered_at no later than ordered_at plus promised_minutes).
Return delivery_status ('on time' or 'late'), rated_deliveries (how many have a non-NULL delivery_rating) and avg_delivery_rating, rounded to 2 decimal places.
Ctrl/⌘ + Enter runs the query. Table and column names are suggested as you type. Press Esc then Tab to leave the editor with the keyboard.
Expected output (2 rows)
Expected output
delivery_status
rated_deliveries
avg_delivery_rating
late
1244
3.71
on time
2200
4.49
Row order doesn’t matter for this question. Numbers are compared with a tiny tolerance; text must match exactly.
Stuck?
Stored on this device only. Your latest query and “solved” status are remembered in this browser only. They don’t sync between devices, and clearing your browser data removes them.