cust_orders (order_id, customer_id, ordered_at, amount) holds orders; amount is NULL while an order hasn't been priced. To spot unusual orders, compare each one with the customer's other orders — all of them, earlier or later, but not the order itself.
- •
avg_other_orders — the average amount of the customer's other orders. Orders with a NULL amount don't count towards any average. NULL when the customer has no other order with an amount. - •
vs_others — amount minus avg_other_orders (NULL if either is NULL).
Both rounded to 2 decimal places.
Columns: order_id, customer_id, amount, avg_other_orders, vs_others. Sort by customer_id, order_id.