PARTITION BY
The part of OVER that splits rows into groups so a window calculation restarts for each group.
In more detail
Unlike GROUP BY it does not collapse the rows: every row stays and sees only its own partition. Rankings with PARTITION BY are independent per group.
Example
COUNT(*) OVER (PARTITION BY customer_id)Related terms
- OVER — The clause that makes a function a window function and defines which rows it can see and in what order.
- window function — A calculation across a set of rows related to the current row that, unlike GROUP BY, keeps every input row in the answer.
- GROUP BY — The clause that splits rows into groups sharing the same values, so aggregates return one result per group.
Taught in
- Window Functions: Replacing Application Loops — PostgreSQL, Indexing & Relational Data Modeling
- Advanced Window Functions: Ranking And Framing — PostgreSQL, Indexing & Relational Data Modeling