COUNT
Description
The COUNT function is used to return the number of rows in a set of data. It can count the total number of rows, the number of non-NULL values in a specified column, or the number of distinct values in a specified column.
Syntax
Parameters
exprN
: An expression of any type.
Return Results
- The return value type is bigint.
- When using the
COUNT(*)
form, all rows are counted, including those with NULL values. - When using the
COUNT(expr1[, expr2, ...])
form, if any column in a row is NULL, that row is ignored. - When using the
COUNT(DISTINCT expr1[, expr2, ...])
form, the specified columns are first deduplicated, and then the number of non-NULL values is counted.
Examples
- Count the number of all rows (including those with NULL values):
- Count the number of non-NULL values in a specified column:
- Count the number of distinct values in a specified column (ignoring NULL values):
- Count the number of specific values in a column:
- Count the number of sales for different products in the sales records (ignore NULL values):