0PricingLogin
SQL Academy · Lesson

Frame Clauses: ROWS vs RANGE

Choose between ROWS BETWEEN and RANGE BETWEEN frame clauses, and understand how each handles duplicates and gaps.

The Frame Inside OVER

A window function evaluates over a frame — a subset of rows from the partition. The frame is defined by:

OVER (
  PARTITION BY ...
  ORDER BY ...
  ROWS BETWEEN <start> AND <end>     -- or RANGE BETWEEN ...
)

Default Frame

If you specify ORDER BY but no frame, the default is:

RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
-- "From the first row up to all rows tied with the current row".

All lessons in this course

  1. Frame Clauses: ROWS vs RANGE
  2. Lag/Lead with Frame Windows
  3. Bucketing with NTILE and Cume_Dist
  4. Real-World Reporting Patterns
← Back to SQL Academy