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
Cleaning and Validating Messy Data
00:00
5 left

Cleaning and Validating Messy Data

MediumSQL · PostgreSQL

Problem

Walk me through how you would clean, validate, and resolve data quality issues in a messy dataset before running statistical analysis.

Write a PostgreSQL query that identifies valid records after applying the stated data-quality rules and summarizes the results by normalized segment.

Output

  1. One row per observed normalized segment
  2. Columns: segment, valid_record_count, invalid_record_count, avg_metric, min_metric, and max_metric
  3. Include segments with no valid records, show unavailable statistics as NULL, and order by segment ascending

Schema

messy_analysis_records
ColumnTypeDescription
record_idPKINTUnique raw record identifier
customer_idINTCustomer identifier from the source file
event_date_textVARCHAR(20)Event date supplied as raw text
metric_textVARCHAR(30)Analysis metric supplied as raw text
segment_textVARCHAR(40)Raw customer segment
source_row_keyVARCHAR(40)Source-system key used to detect duplicate records
loaded_atTIMESTAMPTimestamp when the source record was loaded
customer_reference
ColumnTypeDescription
customer_idPKINTCanonical customer identifier
customer_nameVARCHAR(100)Canonical customer name
expected_segmentVARCHAR(40)Canonical segment used for validation
Tablesmessy_analysis_recordscustomer_reference
Interviewer

Your question is Cleaning and Validating Messy Data. 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.