Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Customers Per Region SQL

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

Your question is Top Customers Per Region SQL. 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

Engie Impact needs a regional view of its highest-consuming customers. Write a PostgreSQL query that aggregates energy consumption by month and ranks customers within each region.

Requirements

  1. Join customer information with energy readings.
  2. Calculate each customer's total consumption for every month in 2025.
  3. Return the top three customers for each region and month, ranking ties by customer_id.
  4. Return the region, month, customer, total consumption, and rank.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer display name
regionVARCHAR(50)Customer's operating region
energy_consumption
ColumnTypeDescription
reading_idPKINTUnique energy reading identifier
customer_idINTCustomer associated with the reading
reading_dateDATEDate on which consumption was recorded
consumption_kwhDECIMAL(12,2)Energy consumption in kilowatt-hours
Tablescustomersenergy_consumption
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results