Overview - Window frame (ROWS BETWEEN, RANGE BETWEEN)
What is it?
Window frames define which rows are included when calculating window functions in SQL. They specify a subset of rows around the current row to perform calculations like sums or averages. The two main types are ROWS BETWEEN and RANGE BETWEEN, which differ in how they select rows. This helps analyze data with context, like running totals or moving averages.
Why it matters
Without window frames, window functions would always consider all rows in a partition, making it impossible to calculate running totals or moving averages efficiently. Window frames let you focus calculations on a specific range of rows, enabling powerful, flexible data analysis. This makes reports and insights more meaningful and precise.
Where it fits
Before learning window frames, you should understand basic SQL SELECT queries, aggregation functions, and window functions without frames. After mastering window frames, you can explore advanced analytics like cumulative distributions, lag/lead functions, and performance tuning of window queries.