A View of Customer Totals
Medium · Views
A view is a saved query with a name: CREATE VIEW name AS SELECT .... Selecting from it runs the query again, so it always shows current data.
Create a view customer_order_totals with the columns customer_id, name, order_count (number of paid orders) and total_spent (sum of total of paid orders). Every customer must appear: a customer without paid orders gets an order_count of 0 and a total_spent of 0.
The check adds one more paid order for customer 1 and then reads the view, so it must be a real view, not a copy of the data.