Your question is Write Rolling Average SQL. Start with the requirements and the two tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Engie Impact uses customer energy data to monitor consumption patterns and support operational planning. Write a PostgreSQL query that calculates a 7-day rolling average of daily energy usage for each customer.
The rolling average should average recorded daily totals within the current date and the preceding six calendar days. Days without readings are not included as zero-usage days.
| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| customer_name | VARCHAR(100) | Customer or account name |
| Column | Type | Description |
|---|---|---|
| reading_idPK | INT | Unique usage reading identifier |
| customer_id | INT | Customer associated with the reading |
| usage_date | DATE | Date of energy usage |
| usage_kwh | NUMERIC(12,2) | Energy consumed in kilowatt-hours |