Reference material for COUNT
Parameter | Description | Supported input types |
---|---|---|
<expression> | The expression to count | Any |
DISTINCT
is being used, only the unique number of rows with no NULL
values are counted. COUNT(*)
returns a total count of all rows in the table, while COUNT(<column_name>)
returns a count of non-null rows in the specified <column_name>
.
COUNT(DISTINCT)
returns exact results. If you do not require a precise result and want to have faster performance, consider using the APPROX_COUNT_DISTINCT function. See below for examples and considerations.NUMERIC
tournaments
:
name | totalprizedollars |
---|---|
The Drifting Thunderdome | 24768 |
The Lost Track Showdown | 5336 |
The Acceleration Championship | 19274 |
The Winter Wilderness Rally | 21560 |
The Circuit Championship | 9739 |
The Singapore Grand Prix | 19274 |
COUNT
returns the total number of rows in the column. As the tournaments
table contains 6 rows, this will be the returned value.
6
A COUNT(DISTINCT)
function on the same column returns the number of unique rows. When applied to the totalprizedollars
column, the value returned is 5
, as there is a repeated number in the column.
5
COUNT(DISTINCT pk)
with exact precision enabled and using default approximation, consider a table, count_test
with 8,388,608 unique pk
values. The APPROX_COUNT_DISTINCT
function returns the same approximate results as the COUNT(DISTINCT)
function with exact precision disabled, so we can see the difference between these methods with the following example.