Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 feedbackSuccess 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 Portfolio Query
00:00
5 left

Top Assets Per Portfolio Query

EasySQL · PostgreSQL

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
Interviewer

Your question is Top Assets Per Portfolio Query. 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.