An incremental orders model (one that rebuilds only recent rows on each run, not the whole table) stores each order with its refunded amount. Each night it rebuilds the orders placed within a lookback window of N days before the latest order date, and nothing older. arrive days or weeks after the order, and finance has noticed that refunded amounts in the model are lower than in the source.
RefundsReturn lookback_days, orders_in_window, refunds_captured, refunds_missed, and refund_amount_missed for lookback windows of 0, 3, 7, 14, and 30 days. Work in calendar dates, taken as the first 10 characters of ordered_at and refunded_at. orders_in_window counts the orders whose order date is on or after the latest order date in orders minus the window, which is what the next run would rebuild. A refund is captured when it was issued no more than that many days after its order was placed, and every other refund is missed. refund_amount_missed is the total amount of the missed refunds, 0 when none are missed, rounded to 2 decimals. Order by lookback_days.
Create a free account to save your progress and reveal the worked answer for this free exercise. The complete practice library is available with Practice Pass or Mastery.