Collection Contents Index CHAPTER 14.  Obtaining Aggregate Data Using aggregate functions to obtain grouped data pdf/chap14.pdf

First Guide to SQL Anywhere Studio
   PART 3. Basic SQL
     CHAPTER 14. Obtaining Aggregate Data       

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 birthdate of the oldest employee, and the birthdate 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 six aggregate functions: MIN, MAX, COUNT, AVG, SUM, and LIST. All but COUNT have the name of a column as a parameter. As you have seen, COUNT has an asterisk as its parameter.


Collection Contents Index CHAPTER 14.  Obtaining Aggregate Data Using aggregate functions to obtain grouped data pdf/chap14.pdf