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 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.