2015. 6. 20. 17:38

http://www.w3schools.com/sql/sql_func_avg.asp


The AVG() Function

The AVG() function returns the average value of a numeric column.

SQL AVG() Syntax

SELECT AVG(column_name) FROM table_name

Demo Database

In this tutorial we will use the well-known Northwind sample database.

Below is a selection from the "Products" table:

ProductIDProductNameSupplierIDCategoryIDUnitPrice
1Chais1110 boxes x 20 bags18
2Chang1124 - 12 oz bottles19
3Aniseed Syrup1212 - 550 ml bottles10
4Chef Anton's Cajun Seasoning2248 - 6 oz jars21.35
5Chef Anton's Gumbo Mix2236 boxes25

SQL AVG() Example

The following SQL statement gets the average value of the "Price" column from the "Products" table:

Example

SELECT AVG(Price) AS PriceAverage FROM Products;

Try it yourself »

The following SQL statement selects the "ProductName" and "Price" records that have an above average price:

Example

SELECT ProductName, Price FROM Products
WHERE Price > (SELECT AVG(Price) FROM Products);

Try it yourself »


'SQL' 카테고리의 다른 글

FIRST() Function  (0) 2015.06.20
COUNT() Function  (0) 2015.06.20
Functions  (0) 2015.06.20
Data Types for Various DBs  (0) 2015.06.20
General Data Types  (0) 2015.06.20
Posted by Name_null