Section: OVER clause fundamentals

Reuse a named window

sql
sql
SELECT order_id,
       amount,
       SUM(amount) OVER w AS running_sum,
       AVG(amount) OVER w AS running_avg
FROM orders
WINDOW w AS (
  PARTITION BY customer_id
  ORDER BY created_at
  ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
);
Explanation

Named windows improve readability when several expressions share the same partition, order, and frame.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing OVER clause fundamentals
Count all rows without collapsing them
Return total row count on every row.
OpenIn sheetsqlsame section
Aggregate within a partition
Compute a per-customer total on every row.
OpenIn sheetsqlsame section
Assign row numbers inside each partition
Number rows in order within each customer.
OpenIn sheetsqlsame section
Explicit ROWS frame
Define exactly which physical rows are included.
OpenIn sheetsqlsame section
Use RANGE for peer-aware frames
Group rows that share the same ordering value.
OpenIn sheetsqlsame section
Exclude the current row from a frame
Compare a row against all earlier rows only.
OpenIn sheetsqlsame section