SQL Basics | Functions | AVG
AVG calculates the average of the data retrieved from a table.
AVG syntax
SELECT AVG("field_name")
FROM "table_name";
AVG example
For example, suppose you want to find the average of the sales field in the table below.
store_information table
| store_name | sales | txn_date |
|---|---|---|
| Los Angeles | 1500 | Jan-05-2018 |
| San Diego | 250 | Jan-07-2018 |
| Los Angeles | 300 | Jan-08-2018 |
| Boston | 700 | Jan-08-2018 |
Enter the following command.
SELECT AVG(sales)
FROM store_information
The result is as follows.
| AVG(sales) |
|---|
| 687.5000 |