Difference between revisions of "COUNT"
From SQLZOO
| (2 intermediate revisions by 2 users not shown) | |||
| Line 10: | Line 10: | ||
</table> | </table> | ||
<h1>COUNT</h1> | <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>[ | + | <li>[[AVG |AVG function]]</li> |
| − | <li>[ | + | <li>[[SUM |SUM function]]</li> |
| − | <li>[ | + | <li>[[MIN |MIN function]]</li> |
</ul> | </ul> | ||
| + | |||
| + | {{Languages}} | ||
Latest revision as of 10:32, 1 October 2012
| COUNT(f) | ||
|---|---|---|
| Engine | OK | Alternative |
| ingres | Yes | |
| mysql | Yes | |
| oracle | Yes | |
| postgres | Yes | |
| sqlserver | Yes | |
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 |
|---|