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
SQL Rolling Average by Asset Class
00:00
5 left

SQL Rolling Average by Asset Class

MediumSQL · PostgreSQL

Problem

Point72's trading analytics team wants to monitor short-term changes in transaction volume across its market data. Write a PostgreSQL query that calculates a seven-day moving average for each ticker, while keeping asset classes separate.

Requirements

  1. Aggregate transaction volume by asset_class, ticker, and trade_date before applying the window function.
  2. Calculate the moving average using the current date and the preceding six calendar days. Include only dates present in the daily aggregate; do not create missing calendar dates.
  3. Partition the window by both asset_class and ticker, and order each partition chronologically by trade_date.
  4. Return the asset class, ticker, trade date, daily volume, and moving average, ordered by asset class, ticker, and trade date.

A NULL volume should be ignored by SUM and AVG, consistent with PostgreSQL aggregate behavior.

Schema

transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
tickerVARCHAR(10)Ticker or traded instrument symbol
asset_classVARCHAR(20)Asset class of the traded instrument
trade_dateDATEDate on which the transaction occurred
volumeDECIMAL(14,2)Transaction volume
Tablestransactions
Interviewer

Your question is SQL Rolling Average by Asset Class. Start with the requirements and the one table 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.