Chapter 8 · Window Functions
54. Moving Average of Daily Bill Totals
Hard40 XPHealthcare
Compute the 7-day moving average of daily billing totals. First aggregate billing by day, then use a window function with ROWS BETWEEN 6 PRECEDING AND CURRENT ROW. Return bill_date, daily_total, and moving_avg_7d (rounded to 2). Order by bill_date.
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.