Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Week-Over-Week Growth

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

Your question is SQL Week-Over-Week Growth. 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

Athelas Operations needs a weekly view of active patient monitoring sessions to identify changes in monitoring volume. Write a PostgreSQL query using the Athelas monitoring session data to calculate week-over-week growth.

Requirements

  1. Count sessions where both the session and the patient are active.
  2. Group counts by calendar week using Monday as the week start.
  3. Compare each week with the immediately preceding week and calculate percentage growth as (current_week - prior_week) / prior_week * 100.
  4. Return weeks in chronological order. Return NULL growth when no prior week exists or the prior count is zero.

Schema

patients
ColumnTypeDescription
patient_idPKINTEGERUnique patient identifier
full_nameVARCHAR(120)Patient full name
statusVARCHAR(20)Current patient status
monitoring_sessions
ColumnTypeDescription
session_idPKINTEGERUnique monitoring session identifier
patient_idINTEGERPatient associated with the session
started_atTIMESTAMPTimestamp when monitoring began
session_statusVARCHAR(20)Current monitoring session status
Tablespatientsmonitoring_sessions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results