Write a SQL query to calculate the rolling average of energy consumption for a set of buildings over a seven-day window.
Use the provided building and energy-consumption data. Aggregate multiple readings for the same building and date before calculating the rolling average. The window includes the current date and the preceding six calendar days.
building_name, reading_date, daily_consumption, and rolling_7_day_avg.building_id, then reading_date.| Column | Type | Description |
|---|---|---|
| building_idPK | INT | Unique building identifier |
| building_name | VARCHAR(100) | Building name |
| region | VARCHAR(50) | Geographic operating region |
| Column | Type | Description |
|---|---|---|
| reading_idPK | INT | Unique energy reading identifier |
| building_id | INT | Building associated with the reading |
| reading_date | DATE | Date of energy consumption |
| energy_kwh | NUMERIC(10,2) | Energy consumed in kilowatt-hours |