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

IDTitlePriceDescription
1Learn SQL20Learn SQL language
2Learn MySQL22Learn MySQL language
3HTML book17Learn HTML
4Learn PHP20Introduction to PHP
5Learn PHP20PHP course
SELECT AVG(price) 
FROM coder_books;

Result

19.800000

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

Result

21.000000