Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Join and Revenue Aggregation

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

Your question is SQL Join and Revenue Aggregation. 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

Genpact Finance Operations needs a simple customer revenue summary for a monthly reporting extract. The source table stores customer identifiers directly with each order.

Task

Write a PostgreSQL query that returns total revenue for each named customer.

Requirements

  1. Exclude orders that do not have a customer name.
  2. Sum all order amounts for each customer, treating a customer with only NULL amounts as having zero revenue.
  3. Return customers ordered from highest to lowest total revenue, with customer name as a deterministic tie-breaker.

Schema

orders
ColumnTypeDescription
order_idPKINTEGERUnique order identifier
customer_nameVARCHAR(100)Customer name associated with the order
order_amountNUMERIC(12,2)Revenue amount, including possible refunds
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