Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Revenue Region by Quarter

Medium
SQL & Data ManipulationJoinsGroup ByAggregations

Problem

Nimbus Retail wants to identify its top-performing sales region for Q1 2024. Write a SQL query to find the region with the highest total completed sales amount during that period.

Requirements

  1. Use only orders with status = 'completed'.
  2. Include only orders with order_date from 2024-01-01 through 2024-03-31.
  3. Sum amount by region using the customer-to-region mapping.
  4. Return the single top-performing region with its total revenue.

Table definitions

regions

columntypedescription
region_idINTPrimary key for each region
region_nameVARCHAR(50)Region name

customers

columntypedescription
customer_idINTPrimary key for each customer
customer_nameVARCHAR(100)Customer name
region_idINTCustomer's assigned region

orders

columntypedescription
order_idINTPrimary key for each order
customer_idINTCustomer placing the order
order_dateDATEDate of the order
amountDECIMAL(10,2)Order amount
statusVARCHAR(20)Order status

Schema

regions
ColumnTypeDescription
region_idPKINTPrimary key for each region
region_nameVARCHAR(50)Name of the sales region
customers
ColumnTypeDescription
customer_idPKINTPrimary key for each customer
customer_nameVARCHAR(100)Customer name
region_idINTRegion assigned to the customer
orders
ColumnTypeDescription
order_idPKINTPrimary key for each order
customer_idINTCustomer who placed the order
order_dateDATEDate the order was created
amountDECIMAL(10,2)Order amount
statusVARCHAR(20)Order status such as completed, pending, or cancelled

You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.

Sign up freeI have an account
SELECT ...
FROM ...
JOIN ... ON ...
GROUP BY ...
HAVING ...
ORDER BY ... DESC;
Sign up to unlock solutions
Next questions
SimilarWebTop Products per Category SalesMediumNTT DATAMonthly Revenue Running Totals by RegionMediumMotorola SolutionsSQL Join Sales and CustomersMedium
PostgreSQL