SQL AVG Function

SQL AVG Function with query example – Avg function returns Average of all values of a column or expression.

  1. AVG function returns the average value of an expression.
  2. AVG function returns NULL If find no matching row exists.
  3. Distinct key word can be used to return the average of the distinct values.

SQL AVG Function syntax

SELECT AVG(Expression)
FROM [Table_Name]
Where  [CONDITION];

AVG function example

In below BOOKS table, we can find the average of prices for all books.

TITLEPRICE
Historica98 
The Castle100 
The Castle150 
Animal Farm300 
Animal Farm120 

Query:

SELECT AVG(PRICE)  FROM BOOKS;

Output:

AVG(price)

153.6

Related Posts