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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Cleaning Messy Healthcare Data
00:00
5 left

Cleaning Messy Healthcare Data

HardSQL · PostgreSQL

Problem

Can you explain a time you had to clean a messy dataset before it could be used for analysis?

For this SQL exercise, clean the raw encounter records and retain only valid encounters for active patients. Standardize the date, encounter type, and status, and keep the most recently ingested record for duplicate patient-date-type combinations.

Output

  1. One row per retained encounter with raw_id, patient_id, canonical_name, encounter_date, encounter_type, and encounter_status.
  2. Exclude invalid, incomplete, inactive-patient, unmatched, and superseded duplicate records.
  3. Order by patient_id, encounter_date, encounter_type, and raw_id ascending.

Schema

raw_encounters
ColumnTypeDescription
raw_idPKINTIdentifier for the raw encounter record
patient_idVARCHAR(20)Raw patient identifier
patient_name_rawVARCHAR(150)Patient name as received in the raw data
encounter_date_rawVARCHAR(20)Encounter date in an inconsistent text format
encounter_type_rawVARCHAR(50)Unstandardized encounter type
status_rawVARCHAR(50)Unstandardized encounter status
ingested_atTIMESTAMPTimestamp when the raw record was ingested
patient_directory
ColumnTypeDescription
patient_idPKVARCHAR(20)Trusted patient identifier
canonical_nameVARCHAR(150)Standardized patient name
activeBOOLEANWhether the patient is currently active
Tablesraw_encounterspatient_directory
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two tables are in the Question tab.

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.