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

avg

Function

The avg function is used to calculate the average value.

Syntax

avg(col), avg(DISTINCT col)

Parameters

Parameter

Mandatory

Description

col

Yes

Column values support all data types and can be converted to DOUBLE type for computation.

Return Values

Returns a value of type DOUBLE.

If col is NULL, the column is excluded from the calculation.

Examples

  • Calculate the average number of items across all warehouses. Example command:
    select avg(items) from warehouse;

    Result:

    _c0        
    100.0      
  • Used with GROUP BY to calculate the average inventory of all items in each warehouse. Example command:
    select warehouseId, avg(items) from warehouse group by warehouseId;

    Result:

    warehouseId _c1
    city1    155       
    city2    101        
    city3    194