Stanford Medicine wants to monitor monthly patient admissions by hospital department. Write a PostgreSQL query that calculates a rolling three-month average for every department, including departments or months with no admissions.
The data includes duplicate monthly records, a null admission count, departments without admissions, and an admission with no matching department.
| Column | Type | Description |
|---|---|---|
| department_idPK | INTEGER | Unique hospital department identifier |
| department_name | VARCHAR(100) | Stanford Medicine department name |
| Column | Type | Description |
|---|---|---|
| admission_idPK | INTEGER | Unique admission aggregate record identifier |
| department_id | INTEGER | Referenced department identifier |
| admission_month | DATE | First day of the month represented by the record |
| admission_count | INTEGER | Number of admissions in the record |