Aggregate · Window
COUNT(*) includes every row. COUNT(value) ignores NULL; with multiple arguments only rows where all arguments are non-NULL contribute. COUNT never returns 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.
Star (aggregate)
Values (aggregate)
Window
- RANGE frames with a numeric or time offset are not supported. Use unique ORDER BY values for calculations that advance one row at a time. DISTINCT is not supported in these window forms.
Window star
- RANGE frames with a numeric or time offset are not supported. Use unique ORDER BY values for calculations that advance one row at a time. DISTINCT is not supported in these window forms.
Arguments
star, window star: Takes no arguments.
Values
Window
Returns
- Type: BIGINT
- Possible values: A nonnegative integer.
- NULL behavior: COUNT(*) includes every row. COUNT(value) ignores NULL; with multiple arguments only rows where all arguments are non-NULL contribute. COUNT never returns NULL.
- Empty input: Returns 0 on an empty global aggregate or empty 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.
- Use DISTINCT in grouped aggregation only. It does not provide duplicate removal in a window call.
Examples
Sample data
All rows
Non-NULL values
Distinct values
Aggregate the sample values
One result per group, including an all-NULL group
Window over all rows in each group
Running window
Sliding window with one preceding row
Only NULL values
Empty filtered sample
COUNT star includes NULL rows
COUNT star in a window includes NULL rows
Limitations
- COUNT(DISTINCT …) is not supported as a window function, with or without ORDER BY.
Last modified on October 15, 2026