Learn From - Interactive SQL



SQL AVG() Function


Used in SQL to find the average value of the specified numeric column in the database table.

SQL AVG() Syntax


SELECT AVG(column_name) FROM table_name where ...

Below is shown the "Orders" table:

OrderID CustomerID Date Amount
D001 C001 4/3/2007 12:00:00 AM 150.23
D002 C003 1/22/2005 12:00:00 AM 123.57
D003 C005 3/19/2003 12:00:00 AM 220.43
D004 C007 7/21/2008 12:00:00 AM 157.72
D005 C008 2/28/2009 12:00:00 AM 223.78
D006 C011 3/21/2005 12:00:00 AM 245.34

Type or Copy the SQL into the Text Editor, click the "View Result" button, to see the result.

To find the average of the Amount column in the Orders table.

Select AVG(Amount) as AverageAmount from Orders;

To retrieve all the records from the Orders table that are equal to or more than the average amount.

Select * from Orders
Where Amount >= (Select AVG(Amount) from Orders);

SQL in Text Editor: