Your question is Rolling 7-Day Average with Window Functions. Start with the requirements and the three 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.
Medpace clinical data analysts need to monitor patient measurements across research sites. Write a PostgreSQL query that calculates each patient's rolling 7-calendar-day average and ranks patients within their site based on their latest available rolling average.
NULL averages must rank last.| Column | Type | Description |
|---|---|---|
| site_idPK | INT | Research site identifier |
| site_name | VARCHAR(100) | Medpace research site name |
| Column | Type | Description |
|---|---|---|
| patient_idPK | INT | Patient identifier |
| site_id | INT | Research site assigned to the patient |
| patient_name | VARCHAR(100) | Patient display name |
| Column | Type | Description |
|---|---|---|
| measurement_idPK | INT | Measurement identifier |
| patient_id | INT | Patient associated with the measurement |
| measurement_date | DATE | Date on which the measurement was recorded |
| measurement_value | NUMERIC(8,2) | Recorded clinical measurement |