A three-order moving average

SQLHard15 min

Your task

For paid orders in date order, return placed_on, total_cents and moving_avg: the average of this order and the two before it, rounded to a whole number.

Tables

customer
idINTEGERnameTEXTcountryTEXTsigned_upTEXT
1AnkaDE2025-12-20
2BoUS2025-12-14
3CyUS2026-01-05
4DaraJP2026-02-01
orders
idINTEGERcustomer_idINTEGERplaced_onTEXTtotal_centsINTEGERstatusTEXT
112026-01-0412000paid
212026-01-193500refunded
322026-01-2189000paid
422026-02-0215000paid
532026-02-144200pending
622026-02-2822000paid
More rows not shown