Write a query to return every row in orders with prev_same_status_amount: the amount of the preceding order having both the same customer_id and the same status.
Sequence each customer-and-status history by order_ts, then order_id, both ascending. Return NULL when that history has no earlier order. Keep every order, including those without a predecessor.
Ordering: Sort by customer_id, then order_ts, then order_id, all ascending.