SUM()
Anonymous contributor
Published May 5, 2021Updated Jul 26, 2022
Contribute to Docs
The SUM()
aggregate function takes the name of a column as an argument and returns the sum of all the value in that column.
Syntax
SELECT SUM(column_name)FROM table_name;
Example
For instance, suppose there’s a transactions
table with the following values:
date | amount |
---|---|
2023-01-30 | 2.75 |
2023-01-31 | 6.00 |
2023-01-31 | 4.20 |
The given query will return the sum of all values from the amount
column:
SELECT SUM(amount)FROM transactions;
The result would be:
SUM(amount) |
---|
12.95 |
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn SQL on Codecademy
- Skill path
Analyze Data with SQL
Learn to analyze data with SQL and prepare for technical interviews.Includes 9 CoursesWith CertificateBeginner Friendly17 hours - Free course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner Friendly5 hours