Return the average (arithmetic mean) of the values for an expression.
AVG | AVERAGE (expression)

AVG and AVERAGE are both supported. The expression must be numeric data type or a time data type.

For example:
premdb=# SELECT AVG(capacity)::INT FROM team WHERE capacity >0;
(1 row)
The following example groups by the city column to return average stadium capacities per city:
premdb=# SELECT city, AVG(capacity)::INT 
FROM team WHERE capacity >0 GROUP BY city ORDER BY 2 DESC;
     city      |  avg  
 Manchester    | 65366
 Newcastle     | 52405
 Sunderland    | 49000
 Liverpool     | 42482
 Leeds         | 39460
 Sheffield     | 36217

Return Types

The return type of the AVG function depends on the input type:
  • AVG(INT2) returns DECIMAL(25,6)
  • AVG(INT4) returns DECIMAL(25,6)
  • AVG(INT8) returns DECIMAL(38,6)
  • AVG(FLOAT4) returns FLOAT4
  • AVG(FLOAT8) returns FLOAT8
  • AVG(DECIMAL(p,s)) returns DECIMAL(p,s)
  • AVG(TIME) returns INTERVAL