Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
7-Day Rolling Resting Heart Rate
00:00
5 left

7-Day Rolling Resting Heart Rate

MediumSQL · PostgreSQL

Problem

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.

Requirements

  1. Join whoop_members to resting_heart_rate and return only active members.
  2. Exclude resting heart rate records where resting_hr is NULL.
  3. Calculate the average over the current date and preceding six calendar days, partitioned by member.
  4. Return results ordered by 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.

Schema

whoop_members
ColumnTypeDescription
user_idPKINTEGERUnique Whoop member identifier
member_nameVARCHAR(100)Member display name
membership_statusVARCHAR(20)Membership state, such as active or inactive
resting_heart_rate
ColumnTypeDescription
reading_idPKINTEGERUnique heart rate reading identifier
user_idINTEGERReferences whoop_members.user_id
measured_onDATEDate on which resting heart rate was measured
resting_hrNUMERIC(5,2)Resting heart rate in beats per minute
Tableswhoop_membersresting_heart_rate
Interviewer

Your question is 7-Day Rolling Resting Heart Rate. Start with the requirements and the two tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.