COUNT_IF() OVER ...

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

Returns the count of rows where the condition is true in the window frame.

Syntax

COUNT_IF(expr) [FILTER (WHERE condition) | WITHIN (WHERE condition)] OVER ([PARTITION BY expr [, ...]] [ORDER BY sort_item [, ...]] [ROWS|RANGE|GROUPS frame])

Notes

  • Counts rows where the boolean expression evaluates to true
  • NULL values are treated as false
  • Always returns BIGINT type
  • Equivalent to COUNT(*) FILTER (WHERE condition) in standard SQL

See also

Examples

FeatureQL
SELECT
    -- Rows with v > 10 so far (1, then 1, …), not id
    f1 := ZIP(ARRAY(1, 2, 3, 4) AS id, ARRAY(30, 10, 20, 5) AS v).TRANSFORM(
        SELECT COUNT_IF(v > 10) OVER (ORDER BY id ASC)
    ).UNWRAP(),
    -- COUNT_IF with FILTER (WHERE id > 2): only id 3–4 enter the frame; still requires v > 10
    f2 := ZIP(ARRAY(1, 2, 3, 4) AS id, ARRAY(30, 10, 20, 5) AS v).TRANSFORM(
        SELECT COUNT_IF(v > 10) FILTER (WHERE id > 2) OVER (ORDER BY id ASC)
    ).UNWRAP()
;
Result
f1 ARRAYf2 ARRAY
[1, 1, 2, 2][null, null, 1, 1]

Last update at: 2026/06/20 10:08:10