Difference between revisions of "AVG"

From SQLZOO
Jump to: navigation, search
(Created page with "<table align='right' border='1'> <caption>Compatibility</caption> <tr><th colspan='3'>AVG(f)</th></tr> <tr><td align='center'>'''Engine'''</td><td align='center'>'''OK'''</td>...")
 
 
(2 intermediate revisions by one user not shown)
Line 9: Line 9:
 
<tr><td align='left'>sqlserver</td><td>Yes</td><td></td></tr>
 
<tr><td align='left'>sqlserver</td><td>Yes</td><td></td></tr>
 
</table>
 
</table>
<h3>AVG</h3>
+
 
 +
<h1>AVG</h1>
 
<p>AVG gives the average (the mean) of a whole column or a group of rows for a single column of values.</p>
 
<p>AVG gives the average (the mean) of a whole column or a group of rows for a single column of values.</p>
 
<p>AVG is an aggregate function it is normally used with GROUP BY.</p>
 
<p>AVG is an aggregate function it is normally used with GROUP BY.</p>
Line 29: Line 30:
 
</source>
 
</source>
 
</div>
 
</div>
 +
 
<p>See also</p>
 
<p>See also</p>
 
<ul>
 
<ul>
   <li>[http://sqlzoo.net/w/index.php/MAX MAX function]</li>
+
   <li>[[MAX |MAX function]]</li>
   <li>[[COUNT function]]</li>
+
   <li>[[COUNT |COUNT function]]</li>
   <li>[http://sqlzoo.net/w/index.php/MIN MIN function]</li>
+
   <li>[[MIN |MIN function]]</li>
 
</ul>
 
</ul>
 +
 +
{{Languages}}

Latest revision as of 16:54, 8 September 2012

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

Language: English  • Deutsch
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense