How would you use SQL window functions to calculate a moving average of energy consumption over the last 30 days?
Assume each row contains one meter's daily reading. Calculate total available consumption per day across meters, then calculate the average of daily totals within the inclusive 30-day period ending on each date.
reading_date, daily_consumption_kwh, and moving_avg_30d_kwh.reading_date ascending.| Column | Type | Description |
|---|---|---|
| reading_idPK | INT | Unique identifier for the consumption reading |
| meter_id | VARCHAR(30) | Identifier of the electric meter |
| reading_date | DATE | Calendar date of the reading |
| consumption_kwh | NUMERIC(12,2) | Energy consumed by the meter in kilowatt-hours |