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 Survey Responses for Reporting
00:00
5 left

Clean Survey Responses for Reporting

HardSQL · PostgreSQL

Problem

You are given raw customer feedback survey data from American Family Insurance touchpoints, along with policyholder and channel reference tables. The dataset contains inconsistent casing, blank strings, duplicate submissions, invalid score values, and incomplete responses. Write a PostgreSQL query that returns one cleaned record per customer for the most recent valid survey submission, standardizes key fields, flags whether the response is complete, and shows the previous valid score for that customer when one exists.

Treat blank strings as missing, normalize response_channel to the mapped channel name when possible, convert score values outside the 0-10 range to NULL, and exclude test submissions. If a customer has multiple submissions on the same day, keep the latest by timestamp and then highest response_id as a tie-breaker.

Schema

survey_responses
ColumnTypeDescription
response_idPKINTUnique survey response identifier
customer_idINTCustomer who submitted the survey
submitted_atTIMESTAMPSubmission timestamp
raw_scoreINTRaw survey score from source data
raw_feedbackTEXTFree-text feedback entered by the customer
raw_statusVARCHAR(20)Raw completion status from the survey platform
response_channelVARCHAR(50)Raw survey channel label
is_testBOOLEANWhether the submission is test data
customers
ColumnTypeDescription
customer_idPKINTCustomer identifier
customer_nameVARCHAR(100)Customer full name
state_codeVARCHAR(2)Customer state abbreviation
policy_statusVARCHAR(20)Current policy status
channel_mapping
ColumnTypeDescription
raw_channelPKVARCHAR(50)Observed raw channel value
standardized_channelVARCHAR(50)Canonical channel name
Tablessurvey_responsescustomerschannel_mapping
Interviewer

Your question is Clean Survey Responses for Reporting. 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.