5.1

Aggregate Functions

Aggregate Functions

Table 1. Aggregate Functions List

Aggregate Function

Output data-type

Result

AVG([DISTINCT] column_values)

numeric

The average of the non-null columns in the expression

SUM([DISTINCT] column_values)

numeric

The total of the non-null columns in the expression

MIN([DISTINCT] column_values)

numeric, date, string

The lowest value off the non-null columns in the expression

MAX([DISTINCT] column_values)

numeric, date, string

The highest value of the non-null columns in the expression

COUNT([DISTINCT] column_values)

numeric

The number of the non-null columns in the expression

COUNT(*)

numeric

The number of rows returned by the query

Code Sample:

USE bike;
SELECT AVG(list_price), SUM(list_price), MIN(list_price), 
    MAX(list_price), COUNT(list_price), COUNT(*)
FROM product;

Output:

ag_01.png

CC BY-NC-ND International 4.0

CC BY-NC-ND International 4.0: This work is released under a CC BY-NC-ND International 4.0 license, which means that you are free to do with it as you please as long as you (1) properly attribute it, (2) do not use it for commercial gain, and (3) do not create derivative works.