Starting here? This lesson is part of a full-length tutorial in using SQL for Data Analysis. Check out the beginning.
AVG is a SQL aggregate function that calculates the average of a selected group of values. It's very useful, but has some limitations. First, it can only be used on numerical columns. Second, it ignores nulls completely. You can see this by comparing these two queries of the Apple stock prices dataset:
SELECT AVG(high) FROM tutorial.aapl_historical_stock_price WHERE high IS NOT NULL
The above query produces the same result as the following query:
SELECT AVG(high) FROM tutorial.aapl_historical_stock_price
There are some cases in which you'll want to treat null values as 0. For these cases, you'll want to write a statement that changes the nulls to 0 (covered in a later lesson.
SQL GROUP BY