MySQL sum() function

The MySQL sum() function is used to return the total summed value of an expression.


SELECT SUM(aggregate_expression)
FROM tables
[WHERE conditions];

Parameter explanation

aggregate_expression: It specifies the column or expression that will be summed.

table_name: It specifies the tables, from where you want to retrieve records. There must be at least one table listed in the FROM clause.

WHERE conditions: It is optional. It specifies the conditions that must be fulfilled for the records to be selected.

MySQL sum() function example

Consider a table named "employees", having the following data.

mysql sum() 1

Execute the following query:

SELECT SUM (working_hours) AS "Total working hours"
FROM employees
WHERE working_hours > 5;


mysql sum() 2
Related Tutorial
Follow Us #
Contents +