The SUM() function returns the sum of an expression when using SELECT.

Structure

SELECT SUM(EXPRESSION)
FROM TABLE
WHERE [CONSTRAINTS]

Example

We will use the same example as in the last post, but this time instead of using the AVG() function, we will use the SUM() function. We will use the same two tables: Positions and Salaries:

SELECT p.position_name, SUM(s.salary) total_salaries from salaries s
JOIN positions p ON p.ID = s.positions_id
WHERE p.position_name = 'Software Engineer'