Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Customer Order Totals

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

Your question is SQL for Customer Order Totals. 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

Business Context

ION's Fidessa platform records customer orders that are used for trading activity analysis. The operations team needs a customer-level summary of order value.

Task

Write a PostgreSQL query that calculates the total order amount for each customer in customer_orders.

Requirements

  1. Return one row per customer, including orders whose customer is unknown.
  2. Sum order_amount for each customer, treating a customer with only NULL amounts as having a total of zero.
  3. Sort the results by total order amount in descending order, then by customer name alphabetically to make ties deterministic.

Schema

customer_orders
ColumnTypeDescription
order_idPKINTEGERUnique order identifier
customer_nameVARCHAR(100)Customer name
order_amountNUMERIC(12,2)Monetary value of the order
order_dateDATEDate the order was submitted
Tablescustomer_orders
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results