Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Handle Missing Values and Datetimes

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

Your question is Handle Missing Values and Datetimes. Start with the requirements and the two 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 values and inconsistent datetime formats in a dataset?

Write a PostgreSQL query that standardizes supported event timestamp formats, identifies invalid or missing timestamps, and flags other missing values without removing source records.

Output

  1. One row per event, ordered by event_id.
  2. Return event_id, normalized vehicle_id, source_name, normalized_event_at, datetime_status, mileage_km, and missing_value_status.
  3. Preserve all events, including records with missing or invalid values.

Schema

raw_vehicle_events
ColumnTypeDescription
event_idPKINTUnique event identifier
vehicle_idVARCHAR(20)Vehicle identifier from the source feed
source_idINTSource system identifier
raw_event_timeVARCHAR(40)Event timestamp received as text
mileage_kmINTVehicle mileage in kilometers
event_sources
ColumnTypeDescription
source_idPKINTUnique source system identifier
source_nameVARCHAR(50)Source system name
Tablesraw_vehicle_eventsevent_sources
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results