WINDOW
The WINDOW clause allows you to specify named windows that can be used within window functions. These are useful when you have multiple window functions, as they allow you to avoid repeating the same window clause.
Examples
The WINDOW clause defines a named window (w) once and reuses it across several window functions — here both rank() and dense_rank() share the same partitioning and ordering instead of repeating the OVER (...) clause:
Query
SELECT name, department, rank() OVER w AS rank, dense_rank() OVER w AS dense_rankFROM employeesWINDOW w AS (PARTITION BY department ORDER BY salary DESC)ORDER BY department, salary DESC, name;Result
name | department | rank | dense_rank-------+-------------+------+------------ Alice | Engineering | 1 | 1 Bob | Engineering | 1 | 1 Carol | Engineering | 3 | 2 Dave | Sales | 1 | 1 Eve | Sales | 2 | 2