Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 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
Build my plan
Cleaning Messy Datasets
00:00
5 left

Cleaning Messy Datasets

HardSQL · PostgreSQL

Problem

Walk us through a time you had to clean a messy dataset before analysis.

Using the supplied appointment and patient tables, write a PostgreSQL query that produces analysis-ready appointment records. Standardize inconsistent dates, statuses, NHS numbers, and durations, remove duplicate appointment records, and exclude records that cannot be validated.

Output

  1. One row per valid, deduplicated appointment, with patient_id, patient_name, appointment_date, appointment_type, status, and duration_minutes.
  2. Include only records with a matched patient, valid date, and recognized status. Order by patient_id, appointment_date, and appointment_type.

Schema

raw_appointments
ColumnTypeDescription
raw_idPKINTIdentifier for the raw appointment record
nhs_number_textVARCHAR(30)Raw NHS number, potentially containing spaces or invalid characters
appointment_date_textVARCHAR(20)Appointment date in an inconsistent text format
appointment_typeVARCHAR(50)Type of appointment
status_textVARCHAR(30)Raw appointment status
duration_textVARCHAR(30)Appointment duration stored as text
source_updated_atTIMESTAMPTimestamp used to select the latest duplicate record
patient_directory
ColumnTypeDescription
patient_idPKINTCanonical patient identifier
nhs_numberVARCHAR(20)Validated NHS number
patient_nameVARCHAR(100)Patient display name
Tablesraw_appointmentspatient_directory
Interviewer

Your question is Cleaning Messy Datasets. 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.