Declaration
SUM([DISTINCT | ALL] expr)
Description
Returns the total number of expr values. If no rows are in the set, NULL is returned. The DISTINCT keyword can be used to find the total number of distinct expr values.
If no matching row is found, this function also 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