Aggregate ยท Window
Aliases: count_if
FALSE and NULL conditions are ignored. Empty input or no true conditions returns 0.
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 within each group
Frame (window)
- For ordered frames with no numeric offsets, rows with the same ORDER BY value are treated together. Use unique ORDER BY values when a running result must advance one row at a time.
Arguments
Aggregate and window
Returns
- Type: BIGINT
- Possible values: A nonnegative count of TRUE conditions, represented as a signed 64-bit integer.
- NULL behavior: FALSE and NULL conditions are ignored. Empty input or no true conditions returns 0.
- Empty input: 0, including an empty window frame.
Properties
Usage notes
- Use an explicit frame when the calculation depends on which rows belong to the window. The examples specify ROWS frames and a unique row ID.
Examples
Sample data
Basic aggregate
Grouped aggregate
Window within each group
Running frame
Sliding frame
All-NULL group
Limitations
- COUNT_IF and COUNTIF do not accept DISTINCT.
- RANGE frames are supported only when both ends are unbounded, covering the entire group. Use an explicit ROWS frame for ordered calculations.
- For ordered frames with no numeric offsets, rows with the same ORDER BY value are treated together. Use unique ORDER BY values when a running result must advance one row at a time.
Last modified on October 15, 2026