SQL SUM()
Preview: Anonymous contributor 1 total contribution
Anonymous contributor
Published May 5, 2021β’Updated Jul 26, 2022
The SUM() aggregate function takes the name of a column as an argument and returns the sum of all the value in that column.
- Learn to analyze data with SQL and prepare for technical interviews.
- Includes 9 CoursesIncludes 9 Courses
- With CertificateWith Certificate
- Beginner Friendly.17 hours17 hours
- In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.
- Beginner Friendly.5 hours5 hours
Syntax
SELECTSUM(column_name)FROM table_name;Copy to clipboardCopy to clipboard
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:
SELECTSUM(amount)FROMtransactions;Copy to clipboardCopy to clipboard
The result would be:
| SUM(amount) |
|---|
| 12.95 |
All contributors
Learn SQL on Codecademy
- Learn to analyze data with SQL and prepare for technical interviews.
- Includes 9 CoursesIncludes 9 Courses
- With CertificateWith Certificate
- Beginner Friendly.17 hours17 hours
- In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.
- Beginner Friendly.5 hours5 hours
