COUNT() OVER ...

All functions > WINDOW FUNCTION > COUNT() OVER ...

Returns the count of rows in the window frame.

Syntax

COUNT([DISTINCT] expr | *) OVER ([PARTITION BY expr [, ...]] [ORDER BY sort_item [, ...]] [ROWS|RANGE|GROUPS frame])

Notes

  • Counts rows over a window
  • NULL values in the expression are excluded from the count
  • Use COUNT(DISTINCT expr) for a running count of distinct non-NULL values
  • Always returns BIGINT type
  • Useful for running counts and row numbering within windows

See also

Examples

FeatureQL
SELECT
    f1 := ZIP(ARRAY[100, 200, 300] AS id, ARRAY['a', 'b', 'c'] AS v).TRANSFORM(SELECT COUNT(v) OVER (ORDER BY id ASC)).UNWRAP(), -- Cumulative non-null row count (1, then 2, …), not id and not the VARCHAR payload
    f2 := ZIP(ARRAY[1, 2, 3, 4] AS id, ARRAY['a', 'b', 'b', 'c'] AS v).TRANSFORM(SELECT COUNT(DISTINCT v) OVER (ORDER BY id ASC)).UNWRAP() -- Per-row exact distinct counts (BIGINTs), not the VARCHAR values in v
;
Result
f1 ARRAYf2 ARRAY
[1, 2, 3][1, 2, 2, 3]

Last update at: 2026/05/26 17:22:09