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
Clean a Messy CSV
00:00
5 left

Clean a Messy CSV

MediumSQL · PostgreSQL

Problem

Describe a time you were given a messy CSV file and had to clean it and generate insights from the data.

Write a PostgreSQL query that cleans the provided service-visit data, excludes records with invalid dates, costs, mileage, statuses, or unmatched model codes, and summarizes valid completed visits.

Output

  1. One row per vehicle model and service month.
  2. Return model_name, service_month, completed_visits, total_cost, and average_cost.
  3. Include only valid completed visits and order by service_month ascending, then model_name ascending.

Schema

raw_service_csv
ColumnTypeDescription
visit_idPKINTUnique service visit identifier
model_codeVARCHAR(20)Vehicle model code as imported from the CSV
visit_date_textVARCHAR(30)Service date in inconsistent text format
odometer_textVARCHAR(30)Mileage value containing possible commas or invalid text
cost_textVARCHAR(30)Service cost containing possible currency symbols or invalid text
status_textVARCHAR(30)Visit status with inconsistent casing or whitespace
model_reference
ColumnTypeDescription
model_codePKVARCHAR(20)Canonical vehicle model code
model_nameVARCHAR(80)Readable vehicle model name
vehicle_segmentVARCHAR(40)Vehicle market segment
Tablesraw_service_csvmodel_reference
Interviewer

Your question is Clean a Messy CSV. 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.