Write a SQL query to find the average chemical dosage per well over a rolling 30-day window.
Use the wells and chemical_dosages tables. Include dosage records associated with a known well, and exclude records with no matching well.
well_name, dosed_at, and rolling_avg_dosagerolling_avg_dosage to two decimal places and order by well_name, dosed_at, and dosage_id| Column | Type | Description |
|---|---|---|
| well_idPK | INT | Unique identifier for the well |
| well_name | VARCHAR(100) | Operational name of the well |
| field_name | VARCHAR(100) | Oilfield containing the well |
| basin | VARCHAR(100) | Production basin |
| Column | Type | Description |
|---|---|---|
| dosage_idPK | INT | Unique identifier for a dosage measurement |
| well_id | INT | Well receiving the chemical dosage |
| dosed_at | TIMESTAMP | Date and time of the dosage measurement |
| chemical_name | VARCHAR(100) | Chemical product used |
| dosage_liters | NUMERIC(10,2) | Chemical dosage amount in liters |