MySQL SQLLesson 36Free preview
MySQL GROUP BY
This lesson is part of MySQL · All levels
Summary
GROUP BY is used to group data rows based on one or more columns, e.g. per city, category, or department. Each group can then be calculated by an aggregate function such as COUNT, SUM, AVG, MAX, and MIN. Without GROUP BY, the aggregate function only produces one line for the entire data.
Key points
- GROUP BY group rows based on the same column value
- Aggregate functions such as COUNT, SUM, AVG, MAX, MIN are calculated per group
- Columns selected in addition to the aggregate results must be in GROUP BY (mode ONLY_FULL_GROUP_BY)
- It can group more than one column, for example GROUP BY city, role
- The group's output can be filtered again by having
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.