⚖️ AVG() – Calculate the Average in SQL

🔧 Quick Syntax

SELECT AVG(column_name)
FROM table_name;

This tells SQL:

“Go through all the numbers in this column and tell me the average.”

🧾 Here’s the Table You’re Working With

You’ve got a table 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 Average Order Value

SELECT AVG(total_amount)
FROM orders;

💡 Output:

34.996

SQL added up all the total_amount values and divided by how many there are. Just like a regular average — but automatic.


✅ What Happens If One of the Values Is NULL?

SELECT AVG(total_amount)
FROM orders;

SQL will ignore any rows where total_amount is NULL and calculate the average from the rest. No errors — just a clean result.


✅ Suppose You Want the Average for Orders Over $30

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

💡 Output:

58.75

Only the qualifying rows (over $30) are included in the average. In this case, just Milo and Lexa.


🧃 Recap – What You Learned

  • AVG() calculates the average of a column
  • NULL values are ignored
  • Combine with WHERE to average specific rows
  • Great for prices, scores, ratings, revenue per user, and more

Leave a Comment

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

Scroll to Top