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
- Join portfolios, assets, and asset performance records.
- Include only performance observations in Q2 2025, using an inclusive start date and exclusive end date.
- Aggregate each asset's
return_pct across the quarter.
- 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.