7/15/25, 10:31 AM SQL AVG() Function
Tutorials Exercises Services Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
SQL AVG() Function
❮ Previous Next ❯
The SQL AVG() Function
The AVG() function returns the average value of a numeric column.
Example Get your own SQL Server
Find the average price of all products:
SELECT AVG(Price)
FROM Products;
Try it Yourself »
Note: NULL values are ignored.
Syntax
[Link] 1/9
7/15/25, 10:31 AM SQL AVG() Function
Tutorials Exercises
SELECT AVG(column_name) Services Sign In
FROM table_name
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
WHERE condition;
Demo Database
Below is a selection from the Products table used in the examples:
ProductID ProductName SupplierID CategoryID Unit Price
1 Chais 1 1 10 boxes x 18
20 bags
2 Chang 1 1 24 - 12 oz 19
bottles
3 Aniseed Syrup 1 2 12 - 550 ml 10
bottles
4 Chef Anton's Cajun 2 2 48 - 6 oz 22
Seasoning jars
5 Chef Anton's Gumbo 2 2 36 boxes 21.35
Mix
ADVERTISEMENT
[Link] 2/9
7/15/25, 10:31 AM SQL AVG() Function
Tutorials Exercises Services Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
Add a WHERE Clause
You can add a WHERE clause to specify conditions:
Example
Return the average price of products in category 1:
SELECT AVG(Price)
FROM Products
WHERE CategoryID = 1;
Try it Yourself »
Use an Alias
Give the AVG column a name by using the AS keyword.
Example
Name the column "average price":
[Link] 3/9
7/15/25, 10:31 AM SQL AVG() Function
SELECT AVG(Price) AS [average price]
Tutorials
FROM Products;
Exercises Services Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
Try it Yourself »
Higher Than Average
To list all records with a higher price than average, we can use the AVG() function in a
sub query:
Example
Return all products with a higher price than the average price:
SELECT * FROM Products
WHERE price > (SELECT AVG(price) FROM Products);
Try it Yourself »
Use AVG() with GROUP BY
Here we use the AVG() function and the GROUP BY clause, to return the average price
for each category in the Products table:
Example
SELECT AVG(Price) AS AveragePrice, CategoryID
FROM Products
GROUP BY CategoryID;
Try it Yourself »
[Link] 4/9
7/15/25, 10:31 AM SQL AVG() Function
You will learn more about the GROUP BY clause later in this tutorial.
Tutorials Exercises Services Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
?
Exercise
What does the SQL AVG() function do?
Returns the sum of a numeric column
Returns the average value of a numeric column
Counts the number of rows in a table
Finds the maximum value in a numeric column
Submit Answer »
❮ Previous Next ❯
Track your progress - it's free! Sign Up Log in
ADVERTISEMENT
[Link] 5/9
7/15/25, 10:31 AM SQL AVG() Function
Tutorials Exercises Services Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
[Link] 6/9
7/15/25, 10:31 AM SQL AVG() Function
COLOR PICKER
Tutorials Exercises Services Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
ADVERTISEMENT
ADVERTISEMENT
[Link] 7/9
7/15/25, 10:31 AM SQL AVG() Function
Tutorials Exercises Services Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
ADVERTISEMENT
PLUS SPACES
GET CERTIFIED FOR TEACHERS
FOR BUSINESS CONTACT US
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
[Link] Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
[Link] 8/9
7/15/25, 10:31 AM SQL AVG() Function
C++ Tutorial
Tutorials jQuery Tutorial
Exercises
Top References
Services Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
[Link] Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference
Top Examples Get Certified
HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
[Link] Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate
FORUM ABOUT ACADEMY
W3Schools is optimized for learning and training. Examples might be simplified to improve
reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot
warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted our terms of use,
cookie and privacy policy.
Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by [Link].
[Link] 9/9