Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL Rolling VWAP Last 30 Minutes
00:00
5 left

SQL Rolling VWAP Last 30 Minutes

HardSQL · PostgreSQL

Problem

Write a SQL query to calculate a rolling VWAP over the last 30 minutes for each instrument. Use the trades table and include only rows with non-null prices and positive quantities. The 30-minute interval includes its lower boundary.

Output

  1. One row per valid trade, with instrument, trade_ts, and rolling_vwap.
  2. rolling_vwap is the volume-weighted average price across that instrument's current and preceding 30-minute trades.
  3. Sort by instrument, trade_ts, and trade_id.

Schema

trades
ColumnTypeDescription
trade_idPKINTEGERUnique trade identifier
instrumentVARCHAR(20)Instrument symbol
trade_tsTIMESTAMPTrade execution timestamp
priceNUMERIC(12,4)Execution price
quantityINTEGERNumber of units traded
Tablestrades
Interviewer

Your question is SQL Rolling VWAP Last 30 Minutes. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.