Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Assets Per Portfolio Query

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

Your question is Top Assets Per Portfolio Query. Start with the requirements and the three 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

Capital Group's investment analytics team needs a quarterly view of the strongest assets held in each portfolio. For this exercise, treat the last quarter as Q2 2025, from April 1 through June 30, 2025.

Write a PostgreSQL query that identifies the top three performing assets in every portfolio.

Requirements

  1. Join portfolios, assets, and asset performance records.
  2. Include only performance observations in Q2 2025, using an inclusive start date and exclusive end date.
  3. Aggregate each asset's return_pct across the quarter.
  4. Rank assets independently within each portfolio and return at most three per portfolio, ordered by performance descending. Use asset_id as a deterministic tie-breaker.

Schema

portfolios
ColumnTypeDescription
portfolio_idPKINTUnique portfolio identifier
portfolio_nameVARCHAR(100)Portfolio display name
assets
ColumnTypeDescription
asset_idPKINTUnique asset identifier
portfolio_idINTPortfolio holding the asset
asset_nameVARCHAR(150)Asset name
tickerVARCHAR(20)Trading symbol
asset_classVARCHAR(50)Asset classification
asset_performance
ColumnTypeDescription
performance_idPKINTUnique performance observation identifier
asset_idINTAsset associated with the observation
observation_dateDATEObservation date
return_pctNUMERIC(8,2)Return percentage for the observation
Tablesportfoliosassetsasset_performance
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results