0% found this document useful (0 votes)
2 views12 pages

Window Functions

Window functions perform calculations across a set of rows related to the current row without collapsing them into a single output, preserving row-level context. They require an OVER() clause and can be categorized into aggregate, ranking, and value functions, with key use cases including running totals, ranking, and trend detection. These functions are efficient for advanced analytics and are supported in MySQL 8.0 and later.

Uploaded by

rekha25jobs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views12 pages

Window Functions

Window functions perform calculations across a set of rows related to the current row without collapsing them into a single output, preserving row-level context. They require an OVER() clause and can be categorized into aggregate, ranking, and value functions, with key use cases including running totals, ranking, and trend detection. These functions are efficient for advanced analytics and are supported in MySQL 8.0 and later.

Uploaded by

rekha25jobs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Window

Functions
Presented by:
Rekha Ravindran
Window
Functions?
Window Function
Components
Categories of
Topics Window
Functions
Key Use Cases
24/06/2025 Why Use
MySQL Technical Presentatio 2
n
3

Introducti A window function performs calculations across a set


of rows related to the current row—called a window—

on
without collapsing them into a single output so that
each row in the result retains its identity
Content
What Are
Window
Functions?
• A window function performs a calculation across a set of rows related
to the current row, without collapsing output into a single result
• Requires an OVER() clause to define the window (rows considered), with
optional PARTITION BY and ORDER BY for grouping and ordering
• Unlike standard aggregates (GROUP BY), window functions preserve row-
level context while adding summary information

24/06/2025 MySQL Technical Presentation 4


-> OVER Clause: essential wrapper defining
scope:
Window Function
- PARTITION BY – divides data into
segments Components
- ORDER BY – sets row sequence
- ROWS or RANGE frame – describes
dynamic window bounds

24/06/2025 MySQL Technical Presentation 5


Categories of Window
Functions
Aggregate windows Ranking functions Value functions
• SUM() • ROW_NUMBER() • LAG()
• AVG() • RANK() • LEAD()
• MIN(), • DENSE_RANK() • FIRST_VALUE()
• MAX(), • NTILE() • LAST_VALUE()
• COUNT(). • NTH_VALUE()

24/06/2025 MySQL Technical Presentation 6


EXAMPLES - Aggregate windows
Aggregate Windows
Aggregate Function
Function

24/06/2025 MySQL Technical Presentation 7


EXAMPLES - Ranking functions

24/06/2025 MySQL Technical Presentation 8


EXAMPLES - Value functions

24/06/2025 MySQL Technical Presentation 9


Key Use
Cases
Running totals &
moving averages:
cumulative measures
over ordered rows
Ranking & top-N
calculations: identify
leaderboards, orders
within groups
Trend detection: using
LAG()/LEAD() to
compare current and
adjacent
Subgrouprows
analysis:
calculate metrics per
partition (e.g.,
department) while
retaining detail
24/06/2025 MySQL Technical Presentation
Why Use Window Functions

• Maintain row context: combine summary and detail in


one query
• Efficient & expressive: replace JOINs/subqueries with
concise syntax
• Advanced analytics: enable sophisticated time-series,
ranking, and comparison logic
• Supported in MySQL 8.0+, aligning with SQL:2003
standard and other engines
24/06/2025 MySQL Technical Presentation 11
Thank you

24/06/2025 MySQL Technical Presentation 12

You might also like