SELECT - aggregate

Short Reference

Syntax

... { MAX( [DISTINCT] col )
    | MIN( [DISTINCT] col )
    | AVG( [DISTINCT] col )
    | SUM( [DISTINCT] col )
    | COUNT( DISTINCT col )
    | COUNT( * )
    | count(*) } ... .


Effect

As many of the specified column labels as you like can be listed in the SELECT command as arguments of the above aggregate expression. In aggregate expressions, a single value is calculated from the values of multiple rows in a column as follows (note that the addition DISTINCT excludes double values from the calculation):

  1. MAX( [DISTINCT] col ) Determines the maximum value of the value in the column col in the resulting set or in the current group.

  2. MIN( [DISTINCT] col ) Determines the minimum value of the content of the column col in the resulting set or in the current group.

  3. AVG( [DISTINCT] col ) Determines the average value of the content of the column col in the resulting set or in the current group. The data type of the column has to be numerical.

  4. SUM( [DISTINCT] col ) Determines the sum of the content of the column col in the resulting set or in the current group. The data type of the column has to be numerical.

  5. COUNT( DISTINCT col ) Determines the number of different values in the column col in the resulting set or in the current group.

  6. COUNT( * ) (or count(*)) Determines the number of rows in the resulting set or in the current group. No column label is specified in this case.

If you are using aggregate expressions, all column labels that are not listed as an argument of an aggregate function are listed after the addition GROUP BY. The aggregate functions evaluate the content of the groups defined by GROUP BY in the database system and transfer the result to the combined rows of the resulting set.

The data type of aggregate expressions with the function MAX, MIN or SUM is the data type of the corresponding column in the ABAP Dictionary. Aggregate expressions with the function AVG have the data type FLTP, and those with COUNT have the data type INT4. The corresponding data object after INTO or APPENDING has to be selected accordingly.

Note the following points when using aggregate expressions: