Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Aggregate Portfolio Account Balances

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

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

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results