Skip to main content
Aggregate · Window
Rows with NULL keys are ignored. A selected value can be NULL. All-NULL keys yield NULL.

Syntax

A window function keeps each input row and adds a result for that row. PARTITION BY groups rows with matching values; without it, all input rows form one group.

Aggregate

Window

  • Use a frame that includes all rows in the group or starts at the first row (UNBOUNDED PRECEDING). Sliding frames that drop earlier rows are not supported. RANGE frames with a numeric or time offset are not supported.

Arguments

Aggregate and window

Returns

  • Type: same SQL type as value
  • NULL behavior: Rows with NULL keys are ignored. A selected value can be NULL. All-NULL keys yield NULL.
  • Empty input: Returns NULL for an empty global aggregate or frame.

Properties

Usage notes

  • INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.
  • Query tools may report a DECIMAL result as DOUBLE or a TIME result as INTEGER. The returned value still keeps its decimal precision and scale, or its time type. A reported type does not convert the value.
  • Supports DISTINCT: Adding DISTINCT does not remove duplicate input values.

Examples

Select by key

NULL selected value

All-NULL ordering keys

Limitations

  • Use a frame that includes all rows in the group or starts at the first row (UNBOUNDED PRECEDING). Sliding frames that drop earlier rows are not supported. RANGE frames with a numeric or time offset are not supported.
  • MAX_BY requires exactly two arguments. A three-argument form is not supported.
  • In grouped calls, DISTINCT does not remove duplicate input values. Selection can still vary when rows are tied or their order changes.
Last modified on October 15, 2026