Skip to main content
All Problems
hard0% acceptance

7-Day Moving Average of Daily Billing

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.

Schema

🔑idINT
🔗visit_idINT
amountREAL
insurance_coveredREAL
patient_responsibilityREAL
statusTEXT
billed_atTEXT
paid_atTEXTNULL
postgresql

Run your query to see results

Press Ctrl + Enter to execute