Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top 10% Customers by Usage

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

Your question is Top 10% Customers by Usage. 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

Pacific Gas and Electric needs a regional view of its highest-consuming customers. Write a PostgreSQL query that identifies the top 10% of customers in the North Bay and Sierra regions using their total electricity consumption during the first quarter of 2025.

Requirements

  1. Join customers with meter_readings and sum each customer's consumption_kwh from January 1 through March 31, 2025.
  2. Rank customers independently within each region by total consumption in descending order.
  3. Return the top 10% of customers per region. Round the threshold up so each region returns at least one customer.
  4. Include the region, customer identifier, customer name, total consumption, regional rank, and regional customer count. Break consumption ties by the lowest customer_id.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique PG&E customer identifier
customer_nameVARCHAR(100)Customer name
regionVARCHAR(50)PG&E service region
meter_readings
ColumnTypeDescription
reading_idPKINTUnique meter reading identifier
customer_idINTReferences customers.customer_id
reading_dateDATEDate of measured consumption
consumption_kwhDECIMAL(10,2)Electricity consumed in kilowatt-hours
Tablescustomersmeter_readings
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results