forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: Su, Xiaomeng <suxiaomeng1@huawei.com> Co-committed-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
4.9 KiB
4.9 KiB
avg
This function is used to return the average value.
Syntax
avg(col), avg(DISTINCT col)
Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
col |
Yes |
All data types |
The value can be of any data type and can be converted to the DOUBLE type for calculation. |
Return Values
The return value is of the DOUBLE type.
Example Code
- Calculates the average number of items across all warehouses. An example command is as follows:
select avg(items) from warehouse;
The command output is as follows:
_c0 100.0
- Calculates the average inventory of all items in each warehouse when used with group by. An example command is as follows:
select warehourseId, avg(items) from warehourse group by warehourseId;
The command output is as follows:
warehouseId _c1 city1 155 city2 101 city3 194
Parent topic: Aggregate Functions