Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Customer Returns

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

Your question is SQL for Customer Returns. 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

ABC Education uses its customer operations data to identify customers with unusually high return activity. Write a PostgreSQL query that returns customers whose percentage of delivered orders with an approved or refunded return exceeds 50%.

Requirements

  1. Consider only orders with order_status = 'delivered'.
  2. Count an order at most once as returned, even if it has multiple return records.
  3. Return the customer ID, name, region, delivered order count, returned order count, return percentage rounded to two decimals, and rank within the customer's region.
  4. Exclude customers with no delivered orders, and sort by return percentage descending, then customer ID ascending.

Schema

customers
ColumnTypeDescription
customer_idPKINTEGERUnique customer identifier
customer_nameVARCHAR(100)Customer's full name
emailVARCHAR(255)Customer email address
regionVARCHAR(50)ABC Education operating region
orders
ColumnTypeDescription
order_idPKINTEGERUnique order identifier
customer_idINTEGERCustomer who placed the order
order_statusVARCHAR(20)Order lifecycle status
returns
ColumnTypeDescription
return_idPKINTEGERUnique return record identifier
order_idINTEGEROrder associated with the return
return_statusVARCHAR(20)Return processing status
Tablescustomersordersreturns
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results