A first look at aggregate functions

Aggregate functions return a single value for a set of rows. If there is no GROUP BY clause, an aggregate function returns a single value for all the rows that satisfy other aspects of the query.

List the number of employees in the company

  • In Interactive SQL, execute the following query:

    SELECT COUNT( * )
       FROM Employees;
    COUNT(*)
    75

    The result set consists of only one column, with title COUNT(*), and one row, which contains the total number of employees.

List the number of employees in the company and the birth dates of the oldest and youngest employee

  • In Interactive SQL, execute the following query:

    SELECT COUNT( * ), MIN( BirthDate ), MAX( BirthDate )
       FROM Employees;
    COUNT(*) MIN(Employees.BirthDate) MAX(Employees.BirthDate)
    75 1936-01-02 1973-01-18

The functions COUNT, MIN, and MAX are called aggregate functions. Aggregate functions summarize information. Other aggregate functions include statistical functions such as AVG, STDDEV, and VARIANCE. All but COUNT require a parameter. See Aggregate functions.