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 Accounts per Strategy
00:00
5 left

Top Accounts per Strategy

MediumSQL · PostgreSQL

Problem

AllianceBernstein needs a daily trading-performance view for accounts managed through its portfolio platforms. Write a PostgreSQL query that aggregates eligible trades by account and trade date, then identifies the highest-performing accounts within each strategy.

Requirements

  1. Join trades to accounts and strategies.
  2. Include only active accounts and trades from January 1 through January 3, 2025.
  3. Aggregate daily trade count, notional volume, and realized P&L per account.
  4. Calculate each account's total P&L across the date range.
  5. Use a window function to rank accounts within each strategy by total P&L, retaining the top two ranks. Preserve ties.
  6. Return daily rows for qualifying accounts, ordered by strategy, performance rank, date, and account.

Schema

strategies
ColumnTypeDescription
strategy_idPKINTUnique strategy identifier
strategy_nameVARCHAR(100)Display name of the investment strategy
asset_classVARCHAR(50)Primary asset class for the strategy
accounts
ColumnTypeDescription
account_idPKINTUnique portfolio account identifier
strategy_idINTAssigned investment strategy
account_nameVARCHAR(100)Portfolio account name
statusVARCHAR(20)Account lifecycle status
portfolio_trades
ColumnTypeDescription
trade_idPKINTUnique trade identifier
account_idINTAccount executing the trade
trade_dateDATETrade execution date
trade_typeVARCHAR(10)Buy or sell indicator
quantityINTNumber of units traded
notional_valueNUMERIC(14,2)Trade notional value
realized_pnlNUMERIC(14,2)Realized profit or loss from the trade
Tablesstrategiesaccountsportfolio_trades
Interviewer

Your question is Top Accounts per Strategy. 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.