Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Link Feedback to Purchase Opportunities

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

Your question is Link Feedback to Purchase Opportunities. 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 purchases and post-purchase feedback for Best Buy shoppers. Write a PostgreSQL query that identifies product categories with the strongest opportunity for action by combining purchasing behavior with customer sentiment. Return, for each category in Q1 2024, the number of distinct purchasing customers, total orders, average rating, count of negative feedback entries (rating = 2 or sentiment = 'negative'), and the negative feedback rate. Only include categories with at least 2 distinct purchasing customers and rank the results from highest negative feedback rate to lowest, breaking ties by total orders descending.

Use the tables below. Feedback may exist without a matching purchase, and some purchases may have no feedback, so your logic should handle both cases correctly.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer full name
membership_tierVARCHAR(20)My Best Buy membership tier
signup_dateDATEDate the customer signed up
purchases
ColumnTypeDescription
purchase_idPKINTUnique purchase identifier
customer_idINTCustomer who made the purchase
product_categoryVARCHAR(50)Best Buy product category
purchase_dateDATEDate of purchase
order_amountDECIMAL(10,2)Total order amount
feedback
ColumnTypeDescription
feedback_idPKINTUnique feedback identifier
purchase_idINTAssociated purchase when available
feedback_dateDATEDate feedback was submitted
ratingINTCustomer rating from 1 to 5
sentimentVARCHAR(20)Derived sentiment label
Tablescustomerspurchasesfeedback
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results