SQL AVG

SQL AVG

The SQL AVG function returns the average in a select query.

AVG syntax

SELECT AVG(table_column)
FROM table_name;

AVG example

Coder books table

ID Title Price Description
1 Learn SQL 20 Learn SQL language
2 Learn MySQL 22 Learn MySQL language
3 HTML book 17 Learn HTML
4 Learn PHP 20 Introduction to PHP
5 Learn PHP 20 PHP course
SELECT AVG(price) 
FROM coder_books;

Result

19.800000

SELECT AVG(price)  
FROM coder_books
WHERE id IN (1,2);

Result

21.000000