Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
SQL for Customer Returns
00:00
5 left

SQL for Customer Returns

MediumSQL · PostgreSQL

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
Interviewer

Your question is SQL for Customer Returns. Start with the requirements and the three tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.