Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top 10 Customers by Sales

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

Your question is Top 10 Customers by Sales. Start with the requirements and the two 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

Design a data schema based on a given case, and write a query/logic to select the top 10 customers by sales volume over the past month.

Asked in the HR onsite 1H stage. Schema design and aggregation/ranking case.

Output

  1. Return one row per customer.
  2. Include customer identifier, customer name, and total sales volume for the past month.
  3. Rank customers from highest to lowest sales volume, and return only the top 10.
  4. Break ties by customer identifier in ascending order.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(255)Customer display name
regionVARCHAR(100)Customer region
created_atDATEDate the customer record was created
orders
ColumnTypeDescription
order_idPKINTUnique order identifier
customer_idINTCustomer who placed the order
order_dateDATEOrder date
sales_amountDECIMAL(12,2)Order sales amount
order_statusVARCHAR(20)Order status such as completed, canceled, or pending
Tablescustomersorders
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results