SQL Aggregate Functions
AVG
Returns the average of a column in the resultset/group.
For example, with the following sample data set:
Field1 | Field2 | Field3 |
23 | 10 | 17 |
17 | 10 | 9 |
5 | 12 | 15 |
SELECT AVG(Field1) returns 15.
COUNT
Returns the number of records in the resultset/group. When used with the optional DISTINCT keyword, COUNT returns the unique number of records in the resultset/group.
This parameter can be either an asterisk (*) or an expression. If an asterisk is used then all rows of the resultset/group are counted regardless of NULL status. If the expression for a row evaluated to NULL, it will not be counted.
For example, with the following sample data set:
Field1 | Field2 | Field3 |
23 | 10 | 17 |
17 | 10 | 9 |
5 | 12 | 15 |
SELECT COUNT(Field2) returns 3.
SELECT COUNT(Distinct Field2) returns 2.
MAX
Returns the largest value of the field in the resultset/group.
For example, with the following sample data set:
Field1 | Field2 | Field3 |
23 | 10 | 17 |
17 | 10 | 9 |
5 | 12 | 15 |
SELECT MAX(Field1) returns 23.
MIN
Returns the smallest value of the field in the resultset/group.
For example, with the following sample data set:
Field1 | Field2 | Field3 |
23 | 10 | 17 |
17 | 10 | 9 |
5 | 12 | 15 |
SELECT MIN(Field1) returns 5.
SUM
Returns the sum total of the field in the resultset/group.
For example, with the following sample data set:
Field1 | Field2 | Field3 |
23 | 10 | 17 |
17 | 10 | 9 |
5 | 12 | 15 |
SELECT SUM(Field1) returns 45.