A first look at aggregate functions

Suppose you want to know how many employees there are. The following statement retrieves the number of rows in the employee table:

SELECT count( * )
FROM employee

count( * )

75

The result returned from this query is a table with only one column (with title count(*)) and one row, which contains the number of employees.

The following command is a slightly more complicated aggregate query:

SELECT   count( * ), 
min( birth_date ),
max( birth_date )
FROM employee

count( * )

min( birth_date )

max( birth_date )

75

1936-01-02

1973-01-18

The result set from this query has three columns and only one row. The three columns contain the number of employees, the birth date of the oldest employee, and the birth date of the youngest employee.

COUNT, MIN, and MAX are called aggregate functions. Each of these functions summarizes information for an entire table. In total, there are seven aggregate functions: MIN, MAX, COUNT, AVG, SUM, STDDEV, and VARIANCE. All of the functions have either the name of a column or an expression as a parameter. As you have seen, COUNT also has an asterisk as its parameter.