Your question is 7-Day Rolling Resting Heart Rate. 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.
Whoop needs a daily view of resting heart rate trends for active members. Write a PostgreSQL query that calculates a 7-day rolling average for each member's recorded resting heart rate.
whoop_members to resting_heart_rate and return only active members.resting_hr is NULL.user_id and measurement date. Round the rolling average to two decimal places.A missing measurement date should not be treated as a zero. The rolling average should use the qualifying observations that exist within the seven-day calendar window.
| Column | Type | Description |
|---|---|---|
| user_idPK | INTEGER | Unique Whoop member identifier |
| member_name | VARCHAR(100) | Member display name |
| membership_status | VARCHAR(20) | Membership state, such as active or inactive |
| Column | Type | Description |
|---|---|---|
| reading_idPK | INTEGER | Unique heart rate reading identifier |
| user_id | INTEGER | References whoop_members.user_id |
| measured_on | DATE | Date on which resting heart rate was measured |
| resting_hr | NUMERIC(5,2) | Resting heart rate in beats per minute |