Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Window Functions for Asset Ranking

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

Your question is Window Functions for Asset Ranking. 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

Write a SQL query using window functions to find the top-performing energy assets per region over the last quarter. Use the energy_assets and asset_performance tables, and treat performance as total production_mwh during the previous calendar quarter.

Output

  1. Return one row per top-performing asset, including ties.
  2. Include region, asset_id, asset_name, total_generation_mwh, and performance_rank.
  3. Sort by region ascending, performance_rank ascending, and asset_id ascending.

Schema

energy_assets
ColumnTypeDescription
asset_idPKINTUnique energy asset identifier
asset_nameVARCHAR(100)Displayed name of the energy asset
regionVARCHAR(50)Operating region for the asset
asset_typeVARCHAR(30)Technology type of the asset
statusVARCHAR(20)Current operating status
asset_performance
ColumnTypeDescription
performance_idPKINTUnique performance reading identifier
asset_idINTReferenced energy asset
reading_dateDATEDate of the production reading
production_mwhDECIMAL(12,2)Energy production in megawatt-hours
Tablesenergy_assetsasset_performance
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results