Beginner

63. SUM Function

Learn how to calculate the total of numeric values using the SUM function.

📘 Lesson 63 of 728 ⏱ 7 min 🎯 Beginner

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.

SQL
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.

Have you finished this lesson?

Introduction to SQL – All Lessons