Skip to content

SUM

  • expression: The column or set of values to be added together. The `expression` is evaluated for each row in the table and the result is summed. If the `expression` results in `NULL`, it is treated as zero. The `expression` must be of type `INT`, `FLOAT`, `DECIMAL`, or any other numeric type.
SELECT SUM(salary) AS TotalSalary
FROM employees;
+--------------+
| TotalSalary |
+--------------+
| 10000000 |
+--------------+

The aforementioned SQL statement calculates the sum of all values in the ‘salary’ column from the ‘employees’ table. The result is then labelled as ‘TotalSalary’.