We can operate on sets of records by using aggregate functions provide by MySQL
Aggregate funtions:
To execute aggregate functions, MySQL scan the whole table and create a new temporary table where all rows from each group are consecutive, and then use this temporary table to discover groups and apply aggregate functions .
If GROUP BY uses index , temporary tables can be replaced by index access also depends on which parts of an index are used in a query, the conditions specified for these parts, and the selected aggregate functions.
To use index , all GROUP BY columns reference attributes from the same index, and that the index stores its keys in order.