Syntax
SUM([DISTINCT | ALL] expr)
Purpose
SUM() returns the sum of expr. If the returned set does not contain any rows, NULL is returned. The DISTINCT keyword can be used to find the sum of distinct values of expr.
If no matching row is 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