Write a SQL query to calculate the rolling average of crop yields over a three-year period for each unique farm region.
Use the crop_yields table. First determine each region's average yield for each year, then calculate the rolling average for the current year and two preceding available years.
farm_region, yield_year, annual_average_yield, and rolling_3_year_averagefarm_region, then yield_year| Column | Type | Description |
|---|---|---|
| yield_idPK | INT | Unique yield observation identifier |
| farm_region | VARCHAR(100) | Farm region where the yield was recorded |
| yield_year | INT | Calendar year of the yield observation |
| yield_tons_per_hectare | NUMERIC(10,2) | Crop yield measured in tons per hectare |