Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
Averages are great for calculating averages of scores, reviews and sales.
To get the average value of a numeric column use the AVG()
function.
SELECT AVG(<numeric column>) FROM <table>;
SELECT AVG(<numeric column>) FROM <table> GROUP BY <other column>;
Cheat Sheets

0:00
There are so

0:01
many helpful functions in SQL that helps us answer all sorts of questions.

0:06
In this video we'll answer questions on averages.

0:11
Let's say we wanted to forecast how much we could expect to

0:15
make when we generate a set and amount of orders.

0:18
What is the average amount people spend per order?

0:22
Here's a simple query for

0:24
selecting the cost at the time of purchase for all orders.

0:28
We can use the aggregate function of average or AVG.

0:34
Let's also provide an understandable label of average in our report used in an alias.

0:41
When we run this, we get the average of all orders.

0:46
If we had a particular target to generate a certain amount of revenue,

0:51
this average could help us determine how many orders we need to achieve that goal.

0:57
How about another question?

0:59
What's the average order per customer?

1:02
We can group by the user_id.

1:09
Let's select the user_id as well.

1:16
Okay, when we run this now we get all users average orders.

1:21
This may help us to dive into people's spending habits.

1:25
To recap, to get the average values

1:28
you can use the AVG function on any numeric column.

1:33
Not specifying your condition will do the full table.

1:37
To find the average on a subset of records, you could add a where clause.

1:42
For example, the average amount spent by each user or

1:47
the average reviews for a particular product.

1:52
In the next video, we'll explore some other mathematical functions

1:55
like finding the maximum or minimum values for a given column or set of results.
You need to sign up for Treehouse in order to download course files.
Sign up