Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rolling 7-Day Patient Visit Average

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Rolling 7-Day Patient Visit Average. 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.

You need to log in / sign up to run or submit.

Problem

How would you use SQL window functions to calculate a rolling 7-day average of patient visits by clinic for Remedy Partners’ analytics?

Use the supplied clinic and visit data. Include participating clinics and every calendar date from the earliest to latest visit date.

Output

  1. One row per clinic and calendar date.
  2. Return clinic_id, clinic_name, visit_date, daily_visits, and rolling_7_day_avg.
  3. Include dates with zero visits, round the average to six decimal places, and order by clinic_id, then visit_date.

Schema

clinics
ColumnTypeDescription
clinic_idPKINTUnique clinic identifier
clinic_nameVARCHAR(100)Clinic display name
patient_visits
ColumnTypeDescription
visit_idPKINTUnique visit identifier
clinic_idINTClinic associated with the visit
patient_idINTPatient associated with the visit
visit_dateDATEDate of the patient visit
visit_typeVARCHAR(50)Type of clinical visit
Tablesclinicspatient_visits
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results