PostgreSQL SyntaxLesson 37Free preview
PostgreSQL GROUP BY
This lesson is part of PostgreSQL · All levels
Summary
GROUP BY groups rows that have the same column value so that the aggregate function is calculated separately per group. Each group produces one line of results, such as a number or average per category. Each non-aggregate column in SELECT must be grouped together to validate the query.
Key points
- GROUP BY groups the rows according to the value of a particular column.
- Each group produces one line of aggregate results.
- The regular column in SELECT should be on the GROUP BY list.
- You can use COUNT, SUM, AVG, MIN, and MAX on each group.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.