The AVG() function returns the average value of a numeric column.
SQL AVG() Syntax:
SELECT AVG (Column) FROM Table
Example
We have the following “Orders” table:
OrderID | Customer | Date | OrderPrice |
---|
1 | Jones | 2012/01/01 | 1000 |
2 | Smith | 2012/01/02 | 1600 |
3 | Watson | 2012/01/02 | 700 |
4 | Jones | 2012/01/03 | 300 |
5 | Brown | 2012/01/03 | 2000 |
6 | Smith | 2012/01/04 | 100 |
Now we want to find the average value of the “OrderPrice” fields.
We use the following SQL statement:
SELECT AVG (OrderPrice) AS (OrderAverage) From Orders
The result-set will look like this:
OrderAverage: 950
Link/cite this page
If you use any of the content on this page in your own work, please use the code below to cite this page as the source of the content.
<a href="https://www.afterhoursprogramming.com/tutorial/sql/sql-avg-function/">SQL AVG FUNCTION</a>
Stewart, Suzy. "SQL AVG FUNCTION". After Hours Programming. Accessed on March 20, 2023. https://www.afterhoursprogramming.com/tutorial/sql/sql-avg-function/.
Stewart, Suzy. "SQL AVG FUNCTION". After Hours Programming, https://www.afterhoursprogramming.com/tutorial/sql/sql-avg-function/. Accessed 20 March, 2023.
Stewart, Suzy. SQL AVG FUNCTION. After Hours Programming. Retrieved from https://www.afterhoursprogramming.com/tutorial/sql/sql-avg-function/.