This function is used to return the number of records.
count([distinct|all] <colname>)
Parameter |
Mandatory |
Description |
---|---|---|
distinct or all |
No |
Determines whether duplicate records should be excluded during counting. all is used by default, indicating that all records will be included in the count. If distinct is specified, only the number of unique values is counted. |
colname |
Yes |
The column value can be of any type. The value can be *, that is, count(*), indicating that the number of all rows is returned. |
The return value is of the BIGINT type.
If the value of colname is NULL, the row is not involved in calculation.
select count(*) from warehouse;
The command output is as follows:
_c0 10
select warehouseId, count(*) from warehouse group by warehouseId;
The command output is as follows:
warehouseId _c1 city1 6 city2 5 city3 6
Example 3: Calculates the number of warehouses through distinct deduplication. An example command is as follows:
select count(distinct warehouseId) from warehouse;
The command output is as follows:
_c0 3