Syntax
SUM([DISTINCT ALL] expr)
Purpose
This function 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 (0.00 sec)
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 (0.00 sec)