SUM()
SUM() is an aggregate function that adds up the values in a numeric column and returns the total. It ignores NULL values.
SQL
Use it to answer questions like 'what is the total revenue?' or 'how many items were sold in all?'. SUM only works on numeric columns.
Paired with GROUP BY, SUM() gives a separate total for each group, such as total sales per month.
Syntax
SELECT SUM(column) FROM table_name;Examples
SQL
SELECT SUM(total) AS revenue
FROM orders;Output:
revenue
-------
1250