acct_orders (order_id, customer_id, ordered_at, amount, status) holds orders. An order counts unless its status is exactly 'cancelled' — an order with a NULL status counts. amount is NULL until an order is priced.
Find the customers whose latest counted order is larger than the average of their earlier counted orders, among customers with at least one counted order in each of March, April and May 2024.
- •The latest order has the most recent
ordered_at; at the same time, the larger order_id is the later one. - •The earlier orders are all of the customer's other counted orders. Their average ignores NULL amounts; a customer with no earlier priced order has no average and is left out.
- •A latest order with a NULL amount can't be compared: leave that customer out.
Columns: customer_id, latest_order_id, latest_amount, prior_avg (rounded to 2 decimal places). Sort by customer_id.