Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Handling Missing Data
00:00
5 left

Handling Missing Data

MediumSQL · PostgreSQL

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
Interviewer

Your question is Handling Missing Data. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.