Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Combine Usage and Survey Feedback

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

Your question is Combine Usage and Survey Feedback. 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 customer activity from ScienceDirect and post-period survey responses. Write a PostgreSQL query that combines the two sources to show, for each customer who submitted a survey in March 2024, their total March usage, the number of distinct active usage days, their latest survey score in March, and a usage segment derived from total usage. Include surveyed customers even if they had no matching usage records.

Use the latest March survey response per customer when multiple responses exist, and classify customers as High Usage for 20+ events, Medium Usage for 5-19 events, and Low Usage for fewer than 5 events. Return the result ordered by survey score descending, then total usage descending, then customer name ascending.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer organization name
institution_typeVARCHAR(50)Institution segment for the customer
sciencedirect_usage
ColumnTypeDescription
usage_idPKINTUnique usage event identifier
customer_idINTCustomer associated with the usage event
usage_dateDATEDate of the usage event
event_typeVARCHAR(50)Type of ScienceDirect activity
article_viewsINTNumber of article views recorded for the event
customer_surveys
ColumnTypeDescription
survey_idPKINTUnique survey response identifier
customer_idINTCustomer who submitted the survey
response_dateDATEDate the survey response was submitted
satisfaction_scoreINTSurvey satisfaction score from 1 to 10
feedback_channelVARCHAR(50)Channel used to collect the response
Tablescustomerssciencedirect_usagecustomer_surveys
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results