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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Cleaning Messy Datasets
00:00
5 left

Cleaning Messy Datasets

MediumSQL · PostgreSQL

Problem

How do you approach cleaning and preparing a large, messy dataset for analysis?

Use the provided raw transaction records and customer directory. Return one cleaned row per latest nonblank transaction key, ignoring records with invalid amounts, nonpositive amounts, or a NULL transaction date.

Output

  1. Columns: transaction_key, customer_code, customer_name, region, transaction_date, amount, normalized_status, and category.
  2. Include customer details when available, normalize status values, and replace missing categories with Unknown.
  3. Sort by transaction_date ascending, then transaction_key ascending.

Schema

raw_transactions
ColumnTypeDescription
record_idPKINTUnique raw record identifier
transaction_keyVARCHAR(20)Business transaction identifier
customer_codeVARCHAR(10)Customer identifier from the source system
amount_textVARCHAR(30)Transaction amount stored as raw text
transaction_date_textVARCHAR(20)Transaction date stored as raw text
status_textVARCHAR(30)Raw transaction status
category_textVARCHAR(40)Raw transaction category
updated_atTIMESTAMPSource record update timestamp
customer_directory
ColumnTypeDescription
customer_codePKVARCHAR(10)Customer identifier
customer_nameVARCHAR(100)Customer display name
regionVARCHAR(30)Customer geographic region
Tablesraw_transactionscustomer_directory
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two tables are in the Question tab.

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.