Learn With Grito

AVG in SQL — The Complete Guide for Data Analysts

AVG tells you what is typical. Learn how to use the SQL average function to measure performance, compare segments, and spot business trends.

Tutorial Series10 Mins ReadSQL Level 2
  • Imagine your manager asks:
  • "What is the average order value this month?"
  • "How much does an average customer spend?"
  • "What is the average salary across departments?"

"How long does delivery usually take?"

  • Notice something interesting.
  • Nobody is asking for the total.
  • Nobody is asking for individual records.
  • They want to understand what is typical.
  • That is exactly what the SQL AVG function is designed to answer.

This is the third article in the SQL Aggregation cluster and builds upon the SQL Aggregate Functions hub, COUNT, and SUM. While COUNT measures volume and SUM measures total value, AVG measures typical performance.

Throughout this SQL series, we'll continue using the Grito Commerce database with familiar tables such as Customers, Orders, Order_Items, Products, Payments, Employees, Departments, Inventory, and Campaigns.

AI Answer Block AVG is an SQL aggregate function that calculates the arithmetic mean of a numeric column by dividing the total of all non-NULL values by the number of non-NULL records. Data analysts use it to measure typical performance, such as average order value, average salary, average delivery time, or average customer spend.

Why AVG matters

Businesses rarely make decisions based only on totals.

  • Imagine these numbers.
  • Total revenue:

₹50,00,000

  • Looks impressive.
  • But now ask:

How many customers generated that revenue?

If only five customers generated ₹50 lakh,

the business story is very different from fifty thousand customers generating the same revenue.

  • That is why averages matter.
  • They provide context.
  • Instead of measuring how much, they measure what is typical.

What AVG does

AVG calculates the arithmetic mean of numeric values.

It adds all non-NULL values together and divides them by the number of non-NULL records.

  • Business examples include:
  • Average order value
  • Average employee salary
  • Average shipping cost
  • Average delivery time
  • Average monthly revenue

Average product price

Whenever you want to understand "normal" performance, AVG is usually the right function.

The core idea behind AVG

  • Think about customer spending.
  • Customer A
  • ₹500
  • Customer B
  • ₹700
  • Customer C
  • ₹800
  • Customer D

₹1,000

Instead of studying every purchase,

AVG summarizes them into one representative value.

Individual Values

AVG()

Typical Value

Business Benchmark

That benchmark becomes the foundation for comparison and decision-making.

  • AVG syntax
  • Basic syntax
  • AVG(column_name)

Example

SQL Query
SELECT AVG(order_total)
FROM Orders;
Business question answered
"What is the average order value?"
How AVG works
Suppose the Orders table contains
Order
Amount
101
₹1,000
102
₹2,000
103
₹3,000
104
₹4,000
SQL calculates
(1000 + 2000 + 3000 + 4000)
÷
4
=
2500
Average Order Value
₹2,500
Instead of four separate values,
SQL returns one representative metric.
The real purpose of AVG
Businesses often compare performance.
Not totals.
Examples
Average salary
↓
HR compares departments.
Average order value
↓
Sales compares customer segments.
Average delivery time
↓
Operations measures logistics.
Average customer rating
↓
Product teams monitor quality.
In every case,
AVG helps identify normal performance.
Visual Framework
Many Individual Values
↓
AVG()
↓
Typical Performance
↓
Business Benchmark
That benchmark is what analysts use to compare teams, products, regions, and time periods.
AVG without GROUP BY
Without GROUP BY,
AVG calculates one overall average.
Example
SELECT AVG(employee_salary)
FROM Employees;
Business question
"What is the average employee salary?"
One answer.
Entire company.
AVG with GROUP BY
Most analytical queries use
AVG
GROUP BY
Example
SELECT department_name,
AVG(employee_salary) AS average_salary
FROM Employees
GROUP BY department_name;
Business question
"What is the average salary in each department?"
Instead of one company-wide average,
SQL returns one average for every department.
Practical Business Examples
Example 1 — Average Order Value
SELECT AVG(order_total) AS average_order_value
FROM Orders;
Business question
"What does a typical customer spend per order?"
Example 2 — Average Salary by Department
SELECT department_id,
AVG(employee_salary) AS average_salary
FROM Employees
GROUP BY department_id;
Business question
"Which department has the highest average salary?"
Example 3 — Average Product Price
SELECT AVG(product_price)
FROM Products;
Business question
"What is the average selling price of products?"
Example 4 — Average Delivery Time
SELECT AVG(delivery_days)
FROM Orders;
Business question
"How long does delivery usually take?"
Example 5 — Average Campaign Spend
SELECT campaign_type,
AVG(marketing_cost)
FROM Campaigns
GROUP BY campaign_type;
Business question
"Which campaign type is most expensive on average?"
AVG with WHERE
WHERE filters rows before calculating the average.
Example
SELECT AVG(order_total)
FROM Orders
WHERE order_status = 'Completed';
Business question
"What is the average value of completed orders?"
Cancelled orders are ignored.
AVG with HAVING
Example
SELECT customer_city,
AVG(order_total) AS average_order
FROM Orders
GROUP BY customer_city
HAVING AVG(order_total) > 3000;
Business question
"Which cities have an average order value greater than ₹3,000?"
This is a common executive reporting query.
AVG and NULL values
Like most aggregate functions,
AVG ignores NULL values.
Example
100
200
NULL
500
Average
(100 + 200 + 500)
÷
3
=
266.67
The NULL value is excluded.
It is not treated as zero.
Understanding this behavior prevents incorrect reporting.
Average does not always tell the full story
One of the biggest misconceptions in analytics is believing that averages always represent reality.
Imagine five customers spend
₹500
₹600
₹700
₹800
₹50,000
The average becomes very high.
But does it describe what most customers spend?
Not really.
One unusually large order can significantly increase the average.
That is why experienced analysts interpret averages carefully rather than accepting them at face value.
Common Business Use Cases
Sales
Average order value
Average customer spend
HR
Average salary
Average experience
Operations
Average delivery time
Average warehouse processing time
Marketing
Average campaign cost
Average conversion rate
Finance
Average invoice amount
Average refund value
Almost every KPI dashboard includes at least one average.
AVG vs SUM
Function
Measures
SUM
Total value
AVG
Typical value
Example
Revenue
₹20 lakh
Average order
₹2,000
One measures total business performance.
The other measures customer behavior.
AVG vs COUNT
Function
Measures
COUNT
Volume
AVG
Typical value
A company may have
100 orders
Average value
₹2,500
Both metrics together provide much stronger insight than either one alone.
Performance Considerations
Like SUM, AVG performs efficiently on most databases.
However,
large analytical queries benefit from:
filtering unnecessary rows with WHERE,
indexing filtered columns,
grouping efficiently,
avoiding unnecessary calculations.
Performance depends more on the query structure than on the function itself.
Common Mistakes
1. Assuming averages represent every customer
They don't.
Averages summarize.
They don't describe every individual observation.
2. Ignoring outliers
Very large or very small values can distort averages.
Always examine the business context.
3. Forgetting NULL handling
AVG ignores NULL values.
Many beginners mistakenly think NULL is treated as zero.
4. Comparing averages without considering sample size
An average based on five customers is not as reliable as one based on fifty thousand.
Volume matters.
That is why analysts often use COUNT alongside AVG.
5. Using averages when totals answer the business question
If management asks for total revenue,
don't return average revenue.
Always answer the business question directly.
Real Analyst Workflow
Imagine the Product Manager asks:
"Which customer segments spend the most on average?"
Your thought process becomes:
The metric is an average.
Use AVG.
Group customers by segment.
Filter relevant transactions.
Compare the averages.
Identify high-value customer groups.
This workflow appears in customer analytics, segmentation, and executive reporting.
Analyst Tip
Whenever you present an average in a report, include the corresponding COUNT whenever possible.
For example:
Average Order Value: ₹2,400
Number of Orders: 8
Without the sample size, averages can easily be misinterpreted. Showing both metrics provides much stronger business context.
The Grito Factor
Some of the most expensive business mistakes happen because leaders rely on averages alone. A department with the highest average sales might have only three employees, while another department with a lower average could generate ten times more total revenue. Great analysts never interpret averages in isolation—they combine them with other metrics to tell the complete story.
Interview Perspective
Interviewers frequently ask questions involving AVG because it tests both SQL knowledge and business understanding.
Common questions include:
How does AVG handle NULL values?
Difference between AVG and SUM.
How would you calculate average salary by department?
How do you filter groups based on average values?
Why can averages sometimes be misleading?
Strong answers discuss both SQL behavior and business interpretation.
Practice Questions
Beginner
Which SQL function calculates the average order value?
How does AVG handle NULL values?
Intermediate
Calculate the average salary for each department.
Find the average delivery time for completed orders only.
Advanced
Show only those cities where the average order value exceeds ₹5,000.
(Hint: Combine AVG, GROUP BY, and HAVING.)
Final Thoughts
AVG helps businesses move beyond totals and understand typical performance.
It transforms thousands of individual transactions into meaningful benchmarks that managers can compare across departments, products, regions, customers, and time periods.
Learning AVG is an important milestone because it teaches you to think not only about how much happened, but also about what usually happens—a perspective that lies at the heart of business analytics.
Continue Your Learning
Next lessons in this cluster:
MIN
MAX
SQL Grouped Analysis Examples
Related lessons:
SQL Aggregate Functions
COUNT
SUM
GROUP BY
HAVING
The next lesson explores MIN, where you'll learn how analysts identify the earliest, smallest, or lowest values in a dataset to answer operational and business questions.

Continue learning

Grit Over Excuses.

— The Grito Team