Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL for Customer Order Totals
00:00
5 left

SQL for Customer Order Totals

EasySQL · PostgreSQL

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
Interviewer

Your question is SQL for Customer Order Totals. Start with the requirements and the one table in the Question tab.

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.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.