sum
This function is used to calculate the total sum.
Syntax
sum(col), sum(DISTINCT col)
Parameters
Parameter |
Mandatory |
Description |
---|---|---|
col |
Yes |
The value can be of any data type and can be converted to the DOUBLE type for calculation. The value can be of the DOUBLE, DECIMAL, or BIGINT type. If the value is of the STRING type, the system implicitly converts it to DOUBLE for calculation. |
Return Values
The return value is of the DOUBLE type.
If the value of col is NULL, the row is not involved in calculation.
Example Code
- Calculates the total number of offerings (items) in all warehouses. An example command is as follows:
select sum(items) from warehouse;
The command output is as follows:
_c0 55357
- When used with group by, it groups all offerings by warehouse (warehouseId) and calculates the total number of offerings in all warehouses. An example command is as follows:
select warehouseId, sum(items) from warehouse group by warehouseId;
The command output is as follows:
warehouseId| _c1 city1 15500 city2 10175 city3 19400
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.