COUNT_IF() GROUP BY ...
All functions > GROUP BY > COUNT_IF() GROUP BY ...
Returns the number of values in the group that are true.
Syntax
COUNT_IF(expr) [ FILTER (WHERE condition) ] [ GROUP BY feature [, feature ...] ]
Notes
- Counts how many values evaluate to TRUE
- Equivalent to COUNT(CASE WHEN expr THEN 1 END)
- NULL and FALSE values are not counted
- Returns 0 if no values are TRUE
- Can be used with WHERE clause to filter before counting
- Can be used with GROUP BY clause for grouped counts
Examples
FeatureQL
SELECT
-- Count of even values
f1 := ZIP(ARRAY(1, 2, 3, 4, 5) AS value).TRANSFORM(
SELECT COUNT_IF(value % 2 = 0)
).UNWRAP_ONE()
;Result
| f1 BIGINT |
|---|
| 2 |