Difference between revisions of "COUNT"

From SQLZOO
Jump to: navigation, search
(Created page with "<table align='right' border='1'> <caption>Compatibility</caption> <tr><th colspan='3'>COUNT(f)</th></tr> <tr><td align='center'>'''Engine'''</td><td align='center'>'''OK'''</t...")
 
 
(3 intermediate revisions by 2 users 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>COUNT</h3>
+
<h1>COUNT</h1>
<p>COUNT finds the number of non-null values in a column.</p>
+
<p>COUNT(column_name) finds the number of non-null values in a column. COUNT(*) also counts the null values.</p>
 
<p>COUNT is an aggregate function it is normally used with GROUP BY.  </p>  
 
<p>COUNT is an aggregate function it is normally used with GROUP BY.  </p>  
 
<pre style='width:50ex'>
 
<pre style='width:50ex'>
Line 29: Line 29:
 
<p>See also</p>
 
<p>See also</p>
 
<ul>
 
<ul>
   <li>[http://sqlzoo.net/w/index.php/AVG AVG function]</li>
+
   <li>[[AVG |AVG function]]</li>
   <li>[http://sqlzoo.net/w/index.php/SUM SUM function]</li>
+
   <li>[[SUM |SUM 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 10:32, 1 October 2012

Compatibility
COUNT(f)
EngineOKAlternative
ingresYes
mysqlYes
oracleYes
postgresYes
sqlserverYes

COUNT

COUNT(column_name) finds the number of non-null values in a column. COUNT(*) also counts the null values.

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

  SELECT region, COUNT(name)
    FROM bbc
   GROUP BY region 

With a GROUP BY region statement each region shows up just once. The COUNT column gives the number of countries for each region.

SELECT region, COUNT(name)
  FROM bbc
 GROUP BY region

See also

Language: English  • Deutsch
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense