aggregateClause

The aggregate clause accumulates a running value across query rows. An optional starting clause provides an initial accumulator value.

Examples

Sum values with starting value

from [Observation] O
  aggregate Total starting 0: $total + O.value

Count distinct values

from [Condition] C
  aggregate distinct Count starting 0: $total + 1

Build a concatenated string

from Codes C
  aggregate Result starting '': $total + C.code + ', '
Railroad Diagram
100%
aggregate all distinct identifier startingClause : expression

scroll to zoom · drag to pan · click green rules or blue tokens to navigate

EBNF

aggregateClause
  : 'aggregate' ('all' | 'distinct')? identifier startingClause? ':' expression
  ;

Used In