Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Top Assets Per Sector SQL
00:00
5 left

Top Assets Per Sector SQL

MediumSQL · PostgreSQL

Problem

Write a SQL query to find the top 3 performing assets in each sector over the last quarter.

Use the provided sector, asset, and performance data. Treat an asset's performance as the sum of its recorded returns during the previous calendar quarter. Exclude assets without a matching sector or performance record.

Output

  1. One row per selected asset, with sector_name, asset_id, asset_name, quarterly_return_pct, and performance_rank.
  2. Include up to three assets per sector, ordered by return descending, with asset_id as the tie-breaker.

Schema

sectors
ColumnTypeDescription
sector_idPKINTUnique sector identifier
sector_nameVARCHAR(100)Sector name
assets
ColumnTypeDescription
asset_idPKINTUnique asset identifier
asset_nameVARCHAR(150)Asset name
sector_idINTAssociated sector identifier
asset_performance
ColumnTypeDescription
performance_idPKINTUnique performance record identifier
asset_idINTAsset identifier
performance_dateDATEDate of the recorded return
return_pctDECIMAL(8,4)Return percentage for the record
Tablessectorsassetsasset_performance
Interviewer

Your question is Top Assets Per Sector SQL. Start with the requirements and the three 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.