Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Clean Survey Responses for Reporting

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

Your question is Clean Survey Responses for Reporting. Start with the requirements and the three 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

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results