Window name clause
Defines a named window that specifies window partition and order clauses for an analytic function. This window is specified in the function's OVER
clause. Named windows can be useful when you write queries that invoke multiple analytic functions with similar OVER
clauses, such as functions that use the same partition (PARTITION BY
) clauses.
Syntax
WINDOW window-name AS ( window-partition-clause [window-order-clause] )
Arguments
WINDOW
window-name
- A window name that is unique within the same query.
-
window-partition-clause [window-order-clause]
-
Clauses to invoke when an
OVER
clause references this window.If the window definition omits a window order clause, the
OVER
clause can specify its own order clause.
Requirements
-
A
WINDOW
clause cannot include a window frame clause. -
Each
WINDOW
clause within the same query must have a unique name. -
A
WINDOW
clause can reference another window that is already named. For example, the following query names windoww1
beforew2
. Thus, theWINDOW
clause that definesw2
can referencew1
:=> SELECT RANK() OVER(w1 ORDER BY sal DESC), RANK() OVER w2 FROM EMP WINDOW w1 AS (PARTITION BY deptno), w2 AS (w1 ORDER BY sal);
Examples
See Named windows.