MSK Institute • Shikohabad
Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Connecting serverPlease wait...
💻 Practical Labs🚀 Free Demo📜 Verified Certificates
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
In intermediate SQL, window functions calculate aggregates across whole partitions. In advanced analytical engineering, you often need to restrict calculations to a moving subset of rows relative to the current row—such as a 7-day rolling average or a trailing 3-order moving sum.
This dynamic sliding subset is called the Window Frame, configured using the ROWS or RANGE sub-clauses inside OVER().
UNBOUNDED PRECEDING: Start from the very first row in the partition.n PRECEDING: Start n rows (or values) before the current row.CURRENT ROW: The current row being evaluated.n FOLLOWING: End n rows (or values) after the current row.UNBOUNDED FOLLOWING: Extend to the very last row in the partition.| Dimension | ROWS | RANGE |
|---|---|---|
| Unit of Measurement | Physical row count | Logical value offsets |
| Tie Handling | Distinguishes identical values row-by-row | Treats rows with identical ORDER BY values as a single peer group |
| Performance | Faster (counts physical offsets) | Slower (evaluates value ranges) |
ORDER BY inside OVER() without declaring a frame, MySQL uses:
RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
This default means that tied values are included together in the running calculation!In MySQL 8.0+, RANGE supports numeric and temporal offsets:
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| None | Cumulative Aggregates: Running Totals & Moving Averages |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.