Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Second-Highest Energy Consumer

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

Your question is Second-Highest Energy Consumer. Start with the requirements and the one table 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

Write a query to find the second-highest energy-consuming household from a customer transactions table at Nextera Energy Services.

Calculate total energy consumption per household. Treat the second-highest value as the second distinct total, and return all households tied at that level.

Output

  1. One row per qualifying household with household_id and total_energy_kwh.
  2. Exclude transactions without a household identifier.
  3. Order by household_id ascending.

Schema

customer_transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
household_idINTHousehold associated with the transaction
energy_kwhDECIMAL(10,2)Energy consumed in kilowatt-hours
transaction_dateDATEDate of the energy transaction
Tablescustomer_transactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results