Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Sales Aggregations

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

Your question is SQL for Sales Aggregations. Start with the requirements and the two tables 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

Sanofi's commercial analytics team needs a regional view of completed sales for calendar year 2025. Write a PostgreSQL query that reports metrics for every sales region, including regions with no qualifying transactions.

Requirements

  1. Return each region's name, total completed sales, and average completed transaction amount.
  2. Include only transactions with status = 'Completed' dated from 2025-01-01 through 2025-12-31.
  3. Preserve regions with no qualifying transactions and show their metrics as 0.00.
  4. Sort by total sales descending, then region name ascending.

Schema

sales_regions
ColumnTypeDescription
region_idPKINTUnique identifier for a sales region
region_nameVARCHAR(100)Commercial region name
sales_transactions
ColumnTypeDescription
transaction_idPKINTUnique identifier for a sales transaction
region_idINTRegion associated with the transaction
product_nameVARCHAR(120)Sanofi product or portfolio name
sale_amountDECIMAL(12,2)Transaction sales amount
transaction_dateDATEDate on which the transaction occurred
statusVARCHAR(20)Transaction processing status
Tablessales_regionssales_transactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results