Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Average Order Value Per Customer

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

Your question is Average Order Value Per Customer. 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

The Zappos Family wants to compare average purchase sizes across customers using order transaction data. Write a PostgreSQL query that calculates the average order value for each customer.

Requirements

  1. Group orders by customer_id.
  2. Calculate the average of order_total, rounded to two decimal places.
  3. Return one row per customer, ordered by average order value from highest to lowest. Place customers whose average is NULL last.

PostgreSQL's AVG ignores NULL order totals. If a customer has no non-NULL order totals, their average should remain NULL.

Schema

orders
ColumnTypeDescription
order_idPKINTEGERUnique order identifier
customer_idINTEGERIdentifier of the customer who placed the order
order_totalNUMERIC(10,2)Total monetary value of the order
order_dateDATEDate the order was placed
Tablesorders
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results