Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rolling 30-Day Trading Volumes

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

Your question is Rolling 30-Day Trading Volumes. Start with the requirements and the two 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

Nasdaq Trade Management needs account-level activity metrics for monitoring trading behavior. Write a PostgreSQL query that calculates rolling 30-day trading volume for active accounts.

Requirements

  1. Include trades only when the related account has status = 'ACTIVE'.
  2. Aggregate multiple trades for the same account and date into daily_volume.
  3. Calculate rolling_30_day_volume as the sum from the current trade date and the preceding 29 calendar days, partitioned by account.
  4. Return results ordered by account_id and trade_date.

Schema

accounts
ColumnTypeDescription
account_idPKINTEGERUnique trading account identifier
account_nameVARCHAR(100)Account display name
statusVARCHAR(20)Current account status
trades
ColumnTypeDescription
trade_idPKINTEGERUnique trade identifier
account_idINTEGERAccount associated with the trade
trade_dateDATECalendar date of the trade
volumeNUMERIC(14,2)Number of shares or contracts traded
Tablesaccountstrades
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results