Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL Join and Revenue Aggregation
00:00
5 left

SQL Join and Revenue Aggregation

EasySQL · PostgreSQL

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
Interviewer

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