Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Handling Missing Data

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

Your question is Handling Missing Data. Start with the requirements and the three 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

How do you handle missing data in a dataset?

Using the provided observation, category, and source data, produce a cleaned result. Treat scores outside the range 0 through 100 as missing, retain every observation, and apply category-level then dataset-level fallbacks for missing scores. Replace missing or blank text values with the appropriate category or generic fallback.

Output

  1. One row per observation, ordered by entity_id, observed_on, and observation_id
  2. Return observation_id, entity_id, observed_on, category_name, cleaned_score, score_was_missing, cleaned_status, source_name, and entity_sequence
  3. Use Unclassified, Unknown, or 0 only when no more specific fallback exists

Schema

observations
ColumnTypeDescription
observation_idPKINTUnique observation identifier
entity_idVARCHAR(20)Entity associated with the observation
category_idINTOptional category reference
observed_onDATEDate of the observation
scoreNUMERIC(6,2)Observed score, expected between 0 and 100
statusVARCHAR(30)Observed status
source_idINTOptional data source reference
categories
ColumnTypeDescription
category_idPKINTUnique category identifier
category_nameVARCHAR(40)Category label
default_statusVARCHAR(30)Fallback status for the category
data_sources
ColumnTypeDescription
source_idPKINTUnique source identifier
source_nameVARCHAR(40)Source label
source_typeVARCHAR(30)Source classification
Tablesobservationscategoriesdata_sources
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results