COUNT_IF() GROUP BY ...
All functions > GROUP BY > COUNT_IF() GROUP BY ...
Returns the number of values in the group that are true.
Syntax
Diagram(
Sequence(
Terminal("COUNT_IF"),
Terminal("("),
NonTerminal("expr"),
Terminal(")"),
Choice(0, Skip(),
Sequence(
Terminal("FILTER"),
Terminal("("),
Terminal("WHERE"),
NonTerminal("condition"),
Terminal(")")
)
),
Choice(0, Skip(),
Sequence(
Terminal("GROUP BY"),
OneOrMore(NonTerminal("feature"), Terminal(","))
)
)
)
)| Parameter | Type | Required | Description |
|---|---|---|---|
expr | BOOLEAN | Yes | The boolean condition to evaluate |
condition | BOOLEAN | No | The condition to filter the values before aggregation |
feature | FEATURE | No | The features to group by (many features are supported) |
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
f1 := ZIP(ARRAY[1,2,3,4,5] AS value).TRANSFORM(SELECT COUNT_IF(value % 2 = 0)).UNWRAP_ONE() -- Count of even values
;Result
| f1 BIGINT |
|---|
| 2 |