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
Adherence Rates Query
00:00
5 left

Adherence Rates Query

HardSQL · PostgreSQL

Problem

Write a SQL query to identify patient adherence rates over a twelve-month treatment cycle.

Use the provided patient, treatment cycle, and dose record data. Treat each cycle as twelve expected monthly treatment periods. A month is completed when at least one dose record for that month has status taken; missing or non-taken records do not count.

Output

  1. One row per treatment cycle.
  2. Columns: patient_id, patient_name, cycle_start, months_expected, months_completed, and adherence_rate_pct.
  3. Include cycles with no completed months, order by adherence rate descending, then patient_id ascending.

Schema

patients
ColumnTypeDescription
patient_idPKINTUnique patient identifier
patient_nameVARCHAR(100)Patient display name
regionVARCHAR(50)Patient region
treatment_cycles
ColumnTypeDescription
cycle_idPKINTUnique treatment cycle identifier
patient_idINTPatient receiving the treatment cycle
cycle_startDATEStart date of the twelve-month cycle
cycle_endDATERecorded end date of the cycle
dose_records
ColumnTypeDescription
dose_idPKINTUnique dose record identifier
patient_idINTPatient associated with the dose
scheduled_dateDATEScheduled date of the dose
statusVARCHAR(20)Dose status, such as taken, missed, or pending
Tablespatientstreatment_cyclesdose_records
Interviewer

Your question is Adherence Rates Query. Start with the requirements and the three 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.