๐น 7. What is a Window Frame?
A Window Frame defines which rows around the current row are included in a window calculation.
Example:
SUM(amount) OVER (
ORDER BY sale_date
ROWS BETWEEN UNBOUNDED PRECEDING
AND CURRENT ROW
)
Let's understand the terms:
โข
ROWS specifies that the frame is based on physical rows.โข
UNBOUNDED PRECEDING starts from the first row in the ordered partition.โข
CURRENT ROW ends at the current row.Other useful frame options:
โข
1 PRECEDING โ One row before the current row.โข
1 FOLLOWING โ One row after the current row.โข
UNBOUNDED FOLLOWING โ Last row in the partition.๐น 8. Window Functions vs GROUP BY
This is one of the most important SQL interview questions.
