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
ExperiencesCoaching
New
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
Get started
Identify Top-Performing Portfolios
00:00
5 left

Identify Top-Performing Portfolios

MediumSQL · PostgreSQL

Problem

Given this schema, write a query to identify top-performing portfolios for Citi's Investment & Asset Management stakeholders.

Use active portfolios with at least one performance record. Calculate each portfolio's average return and average outperformance versus its benchmark across all available performance records. Rank portfolios within each stakeholder group by average outperformance, retaining the top three rank levels. Ties should share a rank.

Output

  1. One row per qualifying portfolio with stakeholder_group, portfolio_id, portfolio_name, average_return_pct, average_outperformance_pct, and performance_rank.
  2. Include only active portfolios in the top three rank levels.
  3. Order by stakeholder_group, performance_rank, and portfolio_id.

Output details

  • Round average_return_pct and average_outperformance_pct to exactly two decimal places, but rank using unrounded average outperformance.
  • Sort stakeholder_group, performance_rank, and portfolio_id in ascending order.
  • Ignore NULL values independently when calculating each average, and require at least one non-NULL performance_id for qualification.

Schema

portfolios
ColumnTypeDescription
portfolio_idPKINTUnique portfolio identifier
portfolio_nameVARCHAR(100)Portfolio name
stakeholder_groupVARCHAR(80)Investment and asset management stakeholder group
statusVARCHAR(20)Portfolio status
portfolio_performance
ColumnTypeDescription
performance_idPKINTUnique performance record identifier
portfolio_idINTReferenced portfolio identifier
performance_dateDATEDate of the performance observation
return_pctDECIMAL(8,2)Portfolio return percentage
benchmark_return_pctDECIMAL(8,2)Benchmark return percentage
assets_under_managementDECIMAL(14,2)Assets under management in millions
Tablesportfoliosportfolio_performance
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two tables are in the Question tab.

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.