The SUM function is an aggregate function that calculates the total of numeric values in a column or expression. NULL values are generally ignored by SUM.
Total values are fundamental to business analysis. Analysts frequently calculate total sales, revenue, expenses, salaries, transaction amounts, and quantities.
A sales analyst wants to calculate the total sales amount generated by all transactions. SUM can add all SalesAmount values together.
SELECT
SUM(SalesAmount) AS TotalSales
FROM Sales;
SUM is widely used for revenue analysis, sales reporting, expense analysis, financial reporting, inventory analysis, and performance dashboards.
- SUM is an aggregate function.
- SUM calculates totals.
- It works with numeric values.
- NULL values are generally ignored.
- SUM can be combined with GROUP BY.
What does SUM do in SQL?
SUM calculates the total of numeric values.
Can SUM work with text columns?
SUM is designed for numeric expressions and cannot normally be used directly to total text values.