Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Clean Survey Responses for Reporting

Hard
SQL & Data ManipulationData WranglingCase WhenAggregationsAsked 1 times

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

You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.

Sign up freeI have an account
SELECT ...
FROM ...
JOIN ... ON ...
GROUP BY ...
HAVING ...
ORDER BY ... DESC;
Sign up to unlock solutions
American Family Insurance Customer Insights Analyst Interview QuestionsAmerican Family Insurance Interview Questions
Next questions
AlphaSenseNormalize Messy CRM Contact DataMediumOrangeClean Customer Feedback RecordsEasyBest BuyProfile Incomplete Customer RecordsEasy
PostgreSQL