PostgreSQL SyntaxLesson 25Free preview
PostgreSQL AVG
This lesson is part of PostgreSQL · All levels
Summary
AVG calculates the average value of a numerical column by dividing the total number by the number of non-P0 values. The result is often a fraction, so it needs to be rounded or converted to show off. This function can also be used with GROUP BY for the average of each group.
Key points
- The AVG calculates the mean and ignores the value.
- The numerator is the sum of the values, the denominator is the sum of the non-NULL values.
- The AVG results on the integer can be cut, use CAST or ROUND for decimal.
- Combined GROUP BY for the average per group.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.