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
Handling Missing or Corrupt Data
00:00
5 left

Handling Missing or Corrupt Data

MediumSQL · PostgreSQL

Problem

How do you handle missing or corrupt data in a large clinical dataset using Python?

For this SQL translation, classify each clinical measurement as valid, missing, or corrupt using the recorded value, test type, verification status, and measurement date. Preserve records whose patient identifier does not match the patient registry.

Output

  1. One row per clinical measurement, with columns lab_id, patient_id, patient_name, test_name, measured_at, cleaned_value, and data_quality_status.
  2. Set cleaned_value to NULL unless the measurement is valid.
  3. Include all measurements, order by patient_id ascending with unmatched patients last, then measured_at ascending with NULL dates last, and lab_id ascending.

Schema

patients
ColumnTypeDescription
patient_idPKINTUnique patient identifier
patient_nameVARCHAR(100)Patient display name
site_codeVARCHAR(20)Clinical site identifier
lab_results
ColumnTypeDescription
lab_idPKINTUnique laboratory result identifier
patient_idINTPatient associated with the measurement
test_nameVARCHAR(50)Clinical test name
measurement_valueDECIMAL(8,2)Numeric laboratory measurement
unitVARCHAR(20)Measurement unit
measured_atDATEDate the measurement was taken
source_statusVARCHAR(20)Source verification status
Tablespatientslab_results
Interviewer

Your question is Handling Missing or Corrupt Data. 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.