Average
Next: SQL COUNT
SQL uses the AVG( ) function to calculate the average of a column. The syntax for using this function is,
SELECT AVG("column_name")
FROM "table_name"
For example, if we want to get the average of all sales from the following table,
Table Store_Information
store_name | Sales | Date |
Los Angeles | $1500 | Jan-05-1999 |
San Diego | $250 | Jan-07-1999 |
Los Angeles | $300 | Jan-08-1999 |
Boston | $700 | Jan-08-1999 |
we would type in
SELECT AVG(Sales) FROM Store_Information
Result:
AVG(Sales) |
|
$687.5 represents the average of all Sales entries: ($1500 + $250 + $300 + $700) / 4.