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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Flag Sellers With High Return Rates
00:00
5 left

Flag Sellers With High Return Rates

MediumSQL · PostgreSQL

Problem

You are given order, return, and seller data. Write a PostgreSQL query that finds sellers with unusually high return rates over the last quarter, where return rate is the number of returned orders divided by total completed orders in that quarter. Return each seller’s ID, seller name, total orders, returned orders, and return rate, and only include sellers whose return rate is above 20%.

Output details

  • Treat DATE '2024-01-01' as today's date.
  • Use an inclusive start of DATE '2024-01-01' and an exclusive end of DATE '2024-04-01'.
  • Name and order the output columns seller_id, seller_name, total_orders, returned_orders, and return_rate.
  • Round return_rate to four decimal places before applying the 0.20 threshold.
  • Sort by return_rate descending, then total_orders descending, then seller_id ascending.
  • Count matching return records without deduplicating orders.

Schema

sellers
ColumnTypeDescription
seller_idPKINTPrimary key for each seller
seller_nameVARCHAR(255)Seller display name
orders
ColumnTypeDescription
order_idPKINTPrimary key for each order
seller_idINTSeller who fulfilled the order
order_dateDATEOrder completion date
order_statusVARCHAR(50)Order status such as completed or canceled
returns
ColumnTypeDescription
return_idPKINTPrimary key for each return
order_idINTOrder that was returned
return_dateDATEDate the return was created
Tablessellersordersreturns
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the three tables are in the Question tab.

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.