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
Aggregate Portfolio Account Balances
00:00
5 left

Aggregate Portfolio Account Balances

MediumSQL · PostgreSQL

Problem

Envestnet portfolio reporting needs a view of client assets consolidated across portfolios. Write a PostgreSQL query that aggregates recorded ending balances by client and asset class for a specified date range, then identifies each client's two highest-balance asset classes.

Requirements

  1. Include only holdings from 2025-01-01 through 2025-03-31, inclusive.
  2. Aggregate balances across all matching portfolios for each client and asset class, treating NULL balances as zero.
  3. Use a window function to rank asset classes within each client by aggregated balance, descending.
  4. Return only the top two asset classes per client, including the number of contributing portfolios, and sort the result by client name, rank, and asset class.

Schema

clients
ColumnTypeDescription
client_idPKINTUnique client identifier
client_nameVARCHAR(100)Client display name
risk_tierVARCHAR(20)Optional client risk classification
portfolios
ColumnTypeDescription
portfolio_idPKINTUnique portfolio identifier
client_idINTOwning client identifier
portfolio_nameVARCHAR(100)Portfolio display name
account_typeVARCHAR(30)Portfolio account type
holdings
ColumnTypeDescription
holding_idPKINTUnique holding snapshot identifier
portfolio_idINTRelated portfolio identifier
as_of_dateDATEDate of the balance snapshot
asset_classVARCHAR(50)Asset class assigned to the holding
ending_balanceNUMERIC(14,2)Ending market value for the snapshot
Tablesclientsportfoliosholdings
Interviewer

Your question is Aggregate Portfolio Account Balances. 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.