Counts the number of rows or not NULL values.Documentation Index
Fetch the complete documentation index at: https://docs.firebolt.io/llms.txt
Use this file to discover all available pages before exploring further.
Syntax
Parameters
| Parameter | Description | Supported input types |
|---|---|---|
<expression> | The expression to count | Any |
<condition> | An optional boolean expression to filter rows used in aggregation | BOOL |
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>.
By default,
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.Return Type
NUMERIC
Example
For this example, see the following tabletournaments:
| 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
Example of COUNT(DISTINCT) vs. APPROX_COUNT_DISTINCT
To understand the difference betweenCOUNT(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.