Updated on 2026-11-06 GMT+08:00

count

Function

The count function is used to return the number of records.

Syntax

count([distinct|all] <colname>)

Parameters

Parameter

Mandatory

Description

distinct or all

No

Specifies whether to remove duplicate records when counting. Default is all, which counts all records.

If distinct is specified, only unique values are counted.

colname

Yes

Column values can be of any type. colname can be *, i.e., count(*), which returns the total number of rows.

Return Values

Returns a value of type BIGINT.

If colname is NULL, that row is excluded from the calculation.

Examples

  • Count the number of records in the warehouse table. Example command:
    select count(*) from warehouse;

    Result:

    _c0         
    10    
  • Used with GROUP BY to group all items by warehouse (warehouseId) and count the number of items in each warehouse. Example command:
    select warehouseId, count(*) from warehouse group by warehouseId;

    Result:

    warehouseId _c1         
    city1   6           
    city2   5           
    city3   6 
  • Use distinct to deduplicate and count the number of warehouses. Example command:
    select count(distinct warehouseId) from warehouse;

    Result:

    _c0          
    3