Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Users Who Purchased But Never Returned

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

Your question is Users Who Purchased But Never Returned. 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

DataAnnotation's purchase analytics team wants to identify users who completed at least one purchase but have never returned any purchase. Write a PostgreSQL query that joins the user, purchase, and return data.

Requirements

  1. Include only users with at least one purchase.
  2. Exclude a user if any of their purchases appears in the returns table.
  3. Return the user's ID, name, number of purchases, and total purchased amount.
  4. Sort the results by user_id in ascending order.

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
full_nameVARCHAR(100)User's full name
emailVARCHAR(255)User email address
signup_dateDATEAccount registration date
statusVARCHAR(20)Current account status
purchases
ColumnTypeDescription
purchase_idPKINTUnique purchase identifier
user_idINTUser who made the purchase
purchase_dateDATEDate of purchase
amountNUMERIC(10,2)Purchase amount
returns
ColumnTypeDescription
return_idPKINTUnique return identifier
purchase_idINTPurchase associated with the return
return_dateDATEDate the purchase was returned
reasonVARCHAR(100)Reason for the return
Tablesuserspurchasesreturns
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results