Using Aggregate Functions to Summarize Data

These functions are also referred to as group functions. They return a value based on the values in a column. (After all, you wouldn't ask for the average of a single field.) The examples in this section use the table TEAMSTATS:

SQL> SELECT * FROM TEAMSTATS;

NAME      POS  AB HITS WALKS SINGLES DOUBLES TRIPLES HR SO
------- ----- --- ---- ----  -----    ------ ------ --- ---
JONES      1B 145  45  34    31       8       1     5   10
DONKNOW    3B 175  65  23    50       10      1     4   15
WORLEY     LF 157  49  15    35        8      3     3   16
DAVID      OF 187  70  24    48        4      0     17  42
HAMHOCKER  3B  50  12  10    10        2      0      0  13
CASEY      DH   1   0   0     0        0      0      0   1

6 rows selected.

COUNT

The function COUNT returns the number of rows that satisfy the condition in the WHERE clause. Say you wanted to know how many ball ...

Get Sams Teach Yourself SQL in 21 Days, Fourth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.