Your question is Rolling Average Admissions SQL. Start with the requirements and the two tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
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 |