Watch the 7.3 Webinar On-Demand
This new release brings updates to Universal Storage, query
optimization, and usability that you won’t want to miss.
Aggregate function. Calculate the sum of a set of numbers. NULL values are ignored. If no values can be summed, this function returns NULL.
SUM ( [DISTINCT] expression )
A double if the input type is double, otherwise decimal.
CREATE TABLE sumptuous (id int primary key, number1 int, number2 int);
INSERT INTO sumptuous VALUES (1, 1024, 4096), (2, 23452, NULL);
SELECT SUM(number1), SUM(number2) FROM sumptuous;
+--------------+--------------+
| SUM(number1) | SUM(number2) |
+--------------+--------------+
| 24476 | 4096 |
+--------------+--------------+