Data Aggregation Functions in SQL

Here you find all data aggregation functions, which are used with the GROUP BY statement within the SELECT command. Theese functions aggregate data or get statistics from groups of rows.

AVG - average

Syntax

Description

    AVG calculates the average of all values in the specifyed column.

    Example:

SELECT AVG(preis)
 FROM torder

Calculates the average of all values of preis.

COUNT - count records and values

Syntax

Description

    COUNT counts the number of records with no NULL-values in the specifyed field or the whole number of records in the table if '*' is used instead of specifying a column.

    Example:

SELECT COUNT(DISTINCT preis)
 FROM torder

Counts all unique values of the column preis of the table torder.

SUM - sum up the values

Syntax

Description

    SUM sums up all values in the specifyed column.

    Example:

SELECT SUM(preis)
 FROM torder

Sums up all values of the column preis.

MIN - minimum value

Syntax

Description

    MIN returns the minimum value of the column.

    Example:

SELECT MIN(preis)
 FROM torder

Returns the minimum value of preis.

MAX - maximum value

Syntax

Description

    MAX returns the maximum value of the selected column.

    Example:

SELECT MAX(preis)
 FROM torder

Returns the maximum value of the column preis.

RANGE - range of values (MAX - MIN)

Syntax

Description

    RANGE calculates the difference between the maximum and the minimum values of the column.

    Example:

SELECT PANGE(preis)
 FROM torder;

Calculates the difference between the biggest and the lowest preis.

STDDEV - standard deviation

Syntax

Description

    STDDEV calculates the standart deviation of the values in the specifyed column. Standart deviation is the square root of variance.

    Example:

SELECT STDDEV(preis)
 FROM torder

Calculate the standart variation of all values of preis.

VARIANCE - variance of values in a column

Syntax

Description

    VARIANCE calculates the variance of the values in the column.

    Example:

SELECT VARIANCE(preis)
 FROM torder

Calculate the variance of all values in the column preis.