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
Aggregate Daily Returns Query
00:00
5 left

Aggregate Daily Returns Query

MediumSQL · PostgreSQL

Problem

Aqr's portfolio tracking system stores portfolio metadata separately from daily return observations. Write a PostgreSQL query that summarizes active portfolios between 2025-01-01 and 2025-01-03.

Requirements

  1. Join portfolio metadata to return observations and exclude inactive portfolios.
  2. Return one row per portfolio and return date, with the summed daily return percentage.
  3. Include the number of non-null return observations and the number of positive observations.
  4. Sort results by return date ascending, then portfolio name ascending. Treat a day containing only null return values as a zero aggregate return.

Schema

portfolios
ColumnTypeDescription
portfolio_idPKINTUnique portfolio identifier
portfolio_nameVARCHAR(100)Aqr portfolio name
portfolio_typeVARCHAR(50)Portfolio strategy classification
is_activeBOOLEANWhether the portfolio is currently active
portfolio_return_observations
ColumnTypeDescription
observation_idPKINTUnique return observation identifier
portfolio_idINTPortfolio associated with the observation
return_dateDATEDate of the return observation
return_pctDECIMAL(10,6)Return percentage for the observation
Tablesportfoliosportfolio_return_observations
Interviewer

Your question is Aggregate Daily Returns Query. Start with the requirements and the two 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.