MySQL SQLLesson 17Free preview
MySQL Aggregate Functions
This lesson is part of MySQL · All levels
Summary
The aggregate function counts a group of rows into one summarized value, such as total, average, sum, smallest, and largest. This function is almost always used with GROUP BY to calculate per group, for example total sales per city. Keep in mind that other columns that do not follow the aggregate function must be included in GROUP BY in order for the result to be valid.
Key points
- The main aggregate functions of MySQL are: COUNT(), SUM(), AVG(), MIN(), and MAX()
- The aggregate function ignores the value of NULL when counting (except COUNT(*) which counts all rows)
- GROUP BY group the rows so that the aggregate functions are calculated per group
- SELECT can only contain regular columns if they are in GROUP BY
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.