PARTITION BY is a sub-clause of the OVER() clause used with window (analytic) functions. It virtually splits the result set into partitions—similar to GROUP BY—but without collapsing rows. Each window function then runs independently inside every partition while retaining the original row granularity. If omitted, the entire result set is treated as one partition. PARTITION BY does not create physical storage partitions and has no effect on table design. It is evaluated after WHERE, GROUP BY, and HAVING, but before ORDER BY at the query level. Multiple window functions in the same SELECT can share or define different PARTITION BY clauses. In Standard SQL, PARTITION BY may be combined with ORDER BY and frame specifications (ROWS or RANGE) to further refine the window. Caveats: columns referenced must be visible to the SELECT list (either base columns or derived aliases defined earlier in the same SELECT item list cannot be reused inside the window); large partitions can consume memory; wrong partitioning may lead to incorrect analytic results.
expr1, expr2, ...
(any) - Expressions that define the logical partition.expr3, ...
(any) - Optional sort order inside each partition.frame_clause
(text) - Optional ROWS/RANGE clause limiting the window frame.OVER clause, WINDOW clause, ORDER BY (window), FRAME clause, GROUP BY, ROW_NUMBER, RANK
SQL:2003 (window function standard)
It lets you run aggregate-style calculations like sums, counts, or ranks while keeping every row, eliminating extra joins or subqueries for many analytics tasks.
No. Use the original column name or wrap the SELECT in a subquery where the alias is materialized, then reference it.
Add a frame clause such as ROWS BETWEEN 3 PRECEDING AND CURRENT ROW inside the OVER() specification.
No. If you omit it, the entire result set is treated as a single partition.