-
COUNT(*)counts all rows in a table, no matter whether they contain NULL values. -
COUNT(expr)counts the number of rows with non-NULL values in a specific column. -
COUNT(DISTINCT expr)counts the number of distinct non-NULL values in a column.
COUNT(DISTINCT expr) is used for exact count distinct. If you require higher count distinct performance, see Use bitmap for exact count discount.
From StarRocks 2.4 onwards, you can use multiple COUNT(DISTINCT) in one statement.
Syntax
Parameters
expr: the column or expression based on which count() is performed. If expr is a column name, the column can be of any data type.
Return value
Returns a numeric value. If no rows can be found, 0 is returned. This function ignores NULL values.Examples
Suppose there is a table namedtest. Query the country, category, and supplier of each order by id.
test.
id column.
category column while ignoring NULL values.
category column.
category and supplier.
id 1004 duplicates with the combination with id 1002. They are counted only once. The combination with id 1007 has a NULL value and is not counted.
Example 6: Use multiple COUNT(DISTINCT) in one statement.