Chapter 8 · Window Functions
51. 7-Day Moving Average of Daily Billing
Hard40 XPHealthcare
Compute a 7-day trailing moving average of total daily billing. First aggregate billing by billed_at date, then compute the moving average over the preceding 6 rows and the current row. Sort by billed_at.
Tables
- PKidINT
- FKvisit_id→ visits.idINT
- amountREAL
- insurance_coveredREAL
- patient_responsibilityREAL
- statusTEXT
- billed_atTEXT
- paid_atTEXT
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.