ANSI SQL Window Functions
SQL2003
allows for a
window_clause
in
aggregate function calls, the addition of which makes those functions
into window functions. Both Oracle and DB2 support this window
function syntax. This section describes how to use the
window_clause
within
Oracle and DB2.
Tip
Oracle tends to refer to window functions as analytic functions.
Window, or analytic, functions are similar to standard aggregate functions in that they operate on multiple rows, or groups of rows, within the result set returned from a query. However, the groups of rows that a window function operates on are defined not by a GROUP BY clause, but by partitioning and windowing clauses. Furthermore, the order within these groups is defined by an ordering clause, but that order only affects function evaluation, and has no effect on the order in which rows are returned by the query.
Tip
Window functions are the last items in a query to be evaluated except for the ORDER BY clause. Because of this late evaluation, window functions cannot be used within the WHERE, GROUP BY, or HAVING clauses.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access