SQL Tutorial

SQL SUM Function

The SQL SUM() function uses to sum the values, here is the syntax:

SUM([DISTINCT]|[ALL] <numeric_expression>)

With employee table

employee_id  name      salary 
-----------  --------  -------
          1  jack      3000.00
          2  mary      2500.00
          3  newcomer  2000.00
          4  anna      2800.00
          5  Tom       2700.00
          6  foo       4700.00

In order to calculate total amount of salary the company has to pay each month for all employees, we can use this query:

SELECT SUM(salary) AS total_salary
FROM employee

Here is the output:

total_salary
------------
    17700.00
Read On