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.

TITLE PRICE
Historica 98
The Castle 100
The Castle 150
Animal Farm 300
Animal Farm 120

Query:

SELECT AVG(PRICE)  FROM BOOKS;

Output:

AVG(price)

153.6