➕ SUM() – Add Up Values in SQL

🔧 Quick Syntax

SELECT SUM(column_name)
FROM table_name;

This tells SQL:

“Go down the column and add up all the numbers you find.”

🧾 Here’s the Table You’re Working With

Your table is called orders:

order_id customer_name total_amount
1Fenn Rask10.00
2Milo Kresh45.00
3Sora Dune15.99
4Lexa Vohn72.50
5Tovi Glint29.99

✅ Suppose You Want the Total of All Orders

SELECT SUM(total_amount)
FROM orders;

💡 Output:

173.48

SQL looked at the total_amount column and added all the values together. Total revenue = done.


✅ What Happens If Some Values Are NULL?

Let’s say one row has total_amount = NULL. SQL won’t freak out — it just skips it.

SELECT SUM(total_amount)
FROM orders;

The sum is still calculated from the non-null values. NULLs are ignored by SUM().


✅ Suppose You Want Total Only for High-Value Orders

You only want to count orders where the total is greater than 30:

SELECT SUM(total_amount)
FROM orders
WHERE total_amount > 30;

💡 Output:

117.50

SQL added just the values that matched the condition — in this case, orders from Milo and Lexa.


🧃 Recap – What You Learned

  • SUM() adds up numbers in a column
  • NULL values are ignored
  • Use WHERE to total specific rows
  • Great for revenue, totals, points, quantity, budgets, and more

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top