expr. You can use the DISTINCT keyword to compute the sum of distinct non-null values.
Syntax
Parameters
expr: the expression that evaluates to a numeric value. Supported data types are TINYINT, SMALLINT, INT, FLOAT, DOUBLE, or DECIMAL.
Return value
Data type mapping between input value and return value:- TINYINT -> BIGINT
- SMALLINT -> BIGINT
- INT -> BIGINT
- FLOAT -> DOUBLE
- DOUBLE -> DOUBLE
- DECIMAL -> DECIMAL
Usage notes
- This function ignores nulls.
- An error is returned if
exprdoes not exist. - If a VARCHAR expression is passed, this function implicitly casts the input into DOUBLE values. If the cast fails, an error is returned.
Examples
-
Create a table named
employees. -
Insert data into
employees. -
Query data from
employees.Text -
Use this function to compute sum.
Example 1: Calculate the total sales of each region.
Example 2: Calculate the total employee income of each region. This function ignores nulls and the income of employee idText
777326is not counted.Example 3: Calculate the total number of hobbies. TheTexthobbycolumn is of the STRING type and will be implicitly converted to DOUBLE during computation.Example 4: UseTextsumwith the WHERE clause to calculate the total income of employees whose monthly income is higher than 30000.Text