SQL SUM Function
Syntax
The SUM function in SQL is used to calculate the total value of a numeric column.
-- Calculate the total of a numeric columnSELECT SUM(column1)FROM table_name;
-- Calculate the total for each groupSELECT column2, SUM(column1)FROM table_nameGROUP BY column2;Example
-- Calculate the total salary of all employeesSELECT SUM(salary)FROM employees;/* Output:| SUM(salary) ||-------------|| 150000 |*/
-- Calculate the total salary for each departmentSELECT department, SUM(salary)FROM employeesGROUP BY department;/* Output:| department | SUM(salary) ||-------------|-------------|| Sales | 50000 || Marketing | 40000 || HR | 60000 |*/