Java Reference
In-Depth Information
The most important uses of the
GROUP BY
clause is to group data for analytical purposes. The
functions used to analyze groups of data are called
aggregate
functions
. The aggregate functions are
discussed in the
next section
.
Aggregate Functions
Aggregate functions
return a single value from an operation on a column of data. This differentiates
them from the arithmetic, logical, and character functions discussed in
Chapter 7
, which operate on
individual data elements. Most relational database management systems support the aggregate
functions listed in
Table 8-2
.
Table 8-2: Commonly Supported Aggregate Functions
Sum
SUM
Average
AVG
COUNT
Count
STDEV
Standard Deviation
MAX
Maximum
Minimum
MIN
Aggregate functions are used to provide statistical or summary information about groups of data
elements. These groups may be created specifically using the
GROUP BY
clause, or the aggregate
functions may be applied to the default group, which is the entire result set.
A good practical example of the use of aggregate functions is the creation of a simple sales report. In
Figure 8-3
, the query creates a result set listing distinct customers and calculating the number and total
cost of the items they have bought.
Figure 8-3:
Using aggregate functions