COUNT() GROUP BY ...

All functions > GROUP BY > COUNT() GROUP BY ...

Returns the number of values in the group.

Syntax

Diagram(
  Sequence(
    Terminal("COUNT"),
    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(","))
      )
    )
  )
)
ParameterTypeRequiredDescription
exprTYesThe expression to count
conditionBOOLEANNoThe condition to filter the values before aggregation
featureFEATURENoThe features to group by (many features are supported)

Notes

  • Counts non-NULL values in the group
  • NULL values are excluded from the count
  • Returns 0 for empty groups
  • Can be used with WHERE clause to filter before counting
  • Can be used with GROUP BY clause for grouped counts
  • Use COUNT(*) to count all rows including NULLs

Examples

FeatureQL
SELECT
    f1 := ZIP(ARRAY[1, 2, 3, 4, 5] AS value).TRANSFORM(SELECT COUNT(value)).UNWRAP_ONE(),  -- Count of values
    f2 := ZIP(ARRAY[1, NULL::BIGINT, 3, NULL::BIGINT, 5] AS value).TRANSFORM(SELECT COUNT(value)).UNWRAP_ONE()  -- Count of values excluding NULLs
;
Result
f1 BIGINTf2 BIGINT
53

Last update at: 2026/03/03 16:47:38
Last updated: 2026-03-03 16:48:19