Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Customers With Most Purchase Transactions

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

Your question is Customers With Most Purchase Transactions. 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

Meta Shops wants to identify customers tagged as Meta Quest Owners who make the most purchase transactions. Write a PostgreSQL query that returns every customer with this tag, including tagged customers who have made no purchases.

Requirements

  1. Filter customers through customer_tags using the exact tag Meta Quest Owners.
  2. Count purchase transactions per matching customer, not total purchase value.
  3. Include tagged customers with zero purchases.
  4. Sort by transaction count descending, then customer_id ascending to break ties.

Schema

customers
ColumnTypeDescription
customer_idPKINTEGERUnique customer identifier
customer_nameVARCHAR(100)Customer display name
customer_tags
ColumnTypeDescription
tag_idPKINTEGERUnique tag record identifier
customer_idINTEGERCustomer associated with the tag
tag_nameVARCHAR(100)Tag assigned to the customer
purchases
ColumnTypeDescription
purchase_idPKINTEGERUnique purchase transaction identifier
customer_idINTEGERCustomer who made the purchase
product_nameVARCHAR(150)Purchased product name
purchased_atDATEDate of the purchase
Tablescustomerscustomer_tagspurchases
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results