AVG

From SQLZOO
Revision as of 09:57, 13 July 2012 by Connor (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Compatibility
AVG(f)
EngineOKAlternative
ingresYes
mysqlYes
oracleYes
postgresYes
sqlserverYes

AVG

AVG gives the average (the mean) of a whole column or a group of rows for a single column of values.

AVG is an aggregate function it is normally used with GROUP BY.

The mean of the values 2, 5, 5 is (2+5+5)/3 = 12/3 = 4, you divide by 3 because there are 3 numbers in this example.

NULL values do not contribute to the calculation.

    SELECT region, AVG(population)
    FROM bbc
   GROUP BY region 

With a GROUP BY region statement each region shows up just once. The AVG column gives the average population per country for each region.

SELECT region, AVG(population)
  FROM bbc
 GROUP BY region

See also

Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense