Quant interview prep guides

Window Functions Quant SQL Interview Guide

Window functions quant SQL interview guide for partition, order, lag, rank, running totals, examples, and mistakes.

Candidates needing ranks, rolling values, lag, and partitioned metrics.

Window functions compute across related rows

Window functions let you calculate ranks, lags, running totals, and partitioned aggregates without collapsing rows like GROUP BY.

Partition and order are the core

PARTITION BY defines independent groups, and ORDER BY defines sequence within each group. Without both, many window results are ambiguous.

Concrete example

To find each symbol latest price, use row_number over partition by symbol ordered by timestamp descending, then keep row number one.

Frames matter for rolling metrics

Running and rolling calculations may need explicit window frames. Defaults vary by database and can surprise candidates.

Common mistakes

Candidates often use lag without sorting by time. A lag only makes sense when the ordering column is correct and unique enough.

Practice the pattern

Use the LeetQuidity curriculum and calibration to turn this topic into a focused practice plan.