← All Tools

SQL Window Function Builder

Compose OVER (PARTITION BY ... ORDER BY ... ROWS BETWEEN ...) clauses visually. See the generated SQL and the result it would produce on sample data — running totals, rankings, lags, and moving averages.

📊 Window Function

⚙️ Window Definition

📋 Generated SQL

🔍 Result on Sample Data

Computed in your browser against a small orders sample. Highlighted column shows the window function output. Horizontal lines mark PARTITION BY boundaries.

💡 Frame Clause Cheatsheet

FrameUse case
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROWRunning total / cumulative sum
ROWS BETWEEN N PRECEDING AND CURRENT ROWTrailing N-row moving average
ROWS BETWEEN N PRECEDING AND N FOLLOWINGCentered window (smoothing)
ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWINGRemaining-rows total
RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROWDefault for aggregates with ORDER BY (peer-group inclusive)