Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top 10 Customers by Spend

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

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

EarthCam wants to identify the customers generating the most revenue from camera, monitoring, and streaming orders. Write a PostgreSQL query that returns the 10 customers with the highest total spend.

Requirements

  1. Group order records by customer_name and calculate total spend with SUM(amount).
  2. Return the top 10 customers, ordered by total spend from highest to lowest. Use customer_name ascending as a deterministic tie-breaker.

A NULL order amount should not contribute to a customer's total. The query should still include that customer if the customer has other valid orders.

Schema

earthcam_orders
ColumnTypeDescription
order_idPKINTUnique order identifier
customer_nameVARCHAR(150)Name of the customer
amountNUMERIC(12,2)Order amount in US dollars
order_dateDATEDate the order was placed
Tablesearthcam_orders
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results