Syntax
SUM([DISTINCT | ALL] expr)
Purpose
Returns the total of expr. If no rows are found in the collection, it returns NULL. The DISTINCT keyword can be used to calculate the total of unique values of expr.
If no matching rows are found, the function returns NULL.
Examples
obclient> SELECT * FROM oceanbasetest;
+------+------+------+
| id | ip | ip2 |
+------+------+------+
| 1 | 4 | NULL |
| 3 | 3 | NULL |
| 4 | 3 | NULL |
+------+------+------+
3 rows in set
obclient> SELECT SUM(ip2),SUM(ip),SUM(DISTINCT(ip)) FROM oceanbasetest;
+----------+---------+-------------------+
| sum(ip2) | sum(ip) | sum(distinct(ip)) |
+----------+---------+-------------------+
| NULL | 10 | 7 |
+----------+---------+-------------------+
1 row in set
