# Group Aggregate C++ Sequence Methods

> All Group Aggregate C++ Sequence methods take an input groupBy sequence argument and produce a result sequence containing the calculated aggregate for each group. The object's sequence is split into groups based on the values in the groupBy sequence which is expected to be ordered.

> Sequence<uint8> GenericSequence::groupAggCount() const
> Returns a sequence with the count of the number of elements in each group
> Sequence<T> groupAggMax(GenericSequence const& groupBy) const
> Returns a sequence with the maximum value for each group of elements
> Sequence<T> groupAggMin(GenericSequence const& groupBy) const
> Returns a sequence with the minimum value for each group of elements
> Sequence<T> groupAggFirst(GenericSequence const& groupBy) const
> Returns a sequence with the first element of each group
> Sequence<T> groupAggLast(GenericSequence const& groupBy) const
> Returns a sequence with the last element of each group
> Sequence<R> groupAggSum(GenericSequence const& groupBy) const
> Returns a sequence with the sum of each group of elements
> Sequence<double> groupAggAvg(GenericSequence const& groupBy) const
> Returns a sequence with the average of each group of elements
> Sequence<double> groupAggVar(GenericSequence const& groupBy) const
> Returns a sequence with the variance of each group of elements
> Sequence<double> groupAggVarSamp(GenericSequence const& groupBy) const
> Returns a sequence with the sample variance of each group of elements
> Sequence<double> groupAggDev(GenericSequence const& groupBy) const
> Returns a sequence with the Standard Deviation of each group of elements
> Sequence<double> groupAggDevSamp(GenericSequence const& groupBy) const
> Returns a sequence with the Sample Standard Deviation of each group of elements
> Sequence<uint4> GenericSequence::groupAggApproxDistinctCount(GenericSequence const& groupBy) const
> Returns a sequence with the approximate count of distinct values for each group
> Sequence<uint4> groupAggApproxDistinctHashValues(GenericSequence const& groupBy) const

> Returns a sequence with the approximate count of distinct values for each group for multiple sequences. Whereas `groupAggApproxDistinctCount()` returns the approximate distinct count for each group of a single sequence, `groupAggApproxDistinctHashValues()` returns the approximate distinct count for multiple sequences.

> Sequence<double> groupAggWavg(GenericSequence const& weight, GenericSequence const& groupBy) const

> Returns the `double` result sequence with the weighted average for each group

> ## Example

> Following is an example code snippet demonstrating a group aggregate function:

>         {
>             mco_trans_h trans;
>             mco_cursor_t quote_cursor;
>             Quote quote;
>             MCO_RET rc;
>             ...
>             rc = mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &trans);
>             if ( MCO_S_OK == rc )
>             {

>                 for (rc = mco_cursor_first(trans, &quote_cursor);
>                     rc != MCO_S_CURSOR_END;
>                     rc = mco_cursor_next(trans, &quote_cursor))
>                 {
>                     Sequence<uint4> day_iterator;
>                     quote.from.cursor(trans, &quote_cursor);

>                     // Calculate aggregate for each group. A group is determined by
>                     // ordered sequence elements with the same value.
>                     // Here calculate the total volume for each month of this year.
>                     quote.day_search(day_iterator, DMY(1,1,2013), MCO_SEQ_BOUNDARY_INCLUSIVE,
>                                 DMY(1,1,2014), MCO_SEQ_BOUNDARY_EXCLUSIVE);
>                     print_sequence(quote, quote.volume_project(day_iterator).groupAggSum<uint8>(
>                                     day_iterator / Sequence<uint4>(100) );
>                 }
>                 mco_trans_rollback(trans);
>             }
>         }