SQL AVG() function
The SQL AVG() function is used to get the average value from the selected rows. The column must have numbers stored as value.
SQL AVG() Example:
Let's assume that you have SQL database that has orders table.
Each order has grand total. You want to get the average value of all the orders.
Use following syntax of SQL AVG() function to get the average value of all orders:
SELECT avg(grand_total) AS orderAverage FROM order;
You can also use SQL AVG() function in HAVING clause to filter the search result.
SELECT customer_name FROM order WHERE grand_total > (SELECT AVG(grand_total) FROM orders);