A group function, is a function, that processes a group of rows and it returns only one value. A group function, is called "group" because, it operates on a group of rows taken from a relational table. In contrast: a row function, operates on a single row and it is applied to each row in a relational table. A relational table can be divided into the groups of rows, and, then a group function is applied to each group of rows in the table.
Assume, that we would like to find the total number of courses, or, in the other words, we would like to count the total number of rows in a relational table: COURSE. To count the total number of rows in a group of rows we use a group function: COUNT. A star is used as an argument of count, because we count the complete rows. In the present case entire relational table: COURSE, is considered as one single group.
In the future, we explain how to use GROUP BY clause, to divide a relational table into many disjoint groups of rows. If we would like to count the total number of values in a single column, then a name of such column must be used as an argument of COUNT function.
It is important to remember, that the repetitions of the values in a column are not removed, and identical values are counted as the separate values. If we would like to count the total number of distinct values, then a keyword DISTINCT, must be used before a name of column.
To count the total numbers of pairs, triples, etc, in a relational table, the pairs, triples, etc, must be concatenated with a row function: CONCAT.
A group function: SUM, can be used to compute summation of the values in a given column, in a given group of rows.
For example, we would like to find the total staff number in all departments. In the other words, we would like to compute the summation of all values in a column: total staff number, in a relational table: DEPARTMENT. To implement such query, we use a group function: SUM, with a name of a column: total staff number, as an argument, for example, see the second SELECT statement in the present slide.
If a column does not have a value, it means that NULL, denoting an empty slot is present in a relational table, then to correctly compute an average of all budgets we apply a row function IF NULL, to a column budget before application of a group function AVG, (it means average). If there is no value in a column budget, then IF NULL function, returns zero. Then zero is used for the computation of an average. In the last example, MAX function, is used to find the largest value in a column total staff number.
Group functions are almost always used to aggregate the values in the columns, and, because of that, such functions are commonly called: aggregation functions.