Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Top 10% Customers by Usage
00:00
5 left

Top 10% Customers by Usage

HardSQL · PostgreSQL

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
Interviewer

Your question is Top 10% Customers by Usage. Start with the requirements and the two tables 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.