Next up we're talking about as a good thing.
Next up we're talking about average.
And as you might have guessed because I've said this for pretty much every video on this section it
doesn't it sounds like.
Actually that's a lie.
It sounds like.
But what it does is average data.
So it will some things together and then divide them based off of how many things added together.
So it's pretty useful if you're trying to do things like find the I don't know average sales for something
in a given month or find the average price of something in a database or the average anything an average
number of users that are average number of followers that your YouTube videos have.
I mean averages are pretty useful in general.
Think of all the times in your life.
Hopefully.
I mean I don't know maybe you don't.
Maybe you never average things but I feel like it's something I find myself doing.
It's a lot of what teachers do is find averages average scores average grades.
OK let's just get back to this.
There are a lot of uses for averages.
It's not a perfect way of getting inside it.
I want to say that you know the average is this amazing all encompassing piece of data but it can be
useful anyway.
So how do we use it.
Also as you might have guessed I'm going to show you how to use it on its own first and then how to
use it with group type.
By now we'll be able to do this pretty quickly and it should service review so we could do something
like this.
Calculate the average released year across all books and that's very simple.
We do a select a Viji average release year from books and as you can see we get nineteen ninety nine
point seven eight nine five.
And it's important to note yes there is a decimal.
And it goes out to four places here.
We'll talk more about different types of data data types in a coming election.
Well we'll talk about the differences between integers and the ways of storing decimals.
But for now it's important that you notice when you do average it doesn't round things up to a whole
number.
It gives you four decimal points.
You can also do things like select the average page count from all of our books which is 348 point five
seven eight nine pages.
OK.
So now let's see how to use it with Group.
That's a more common application.
How do we do something like calculate the average stock quantity for books released in the same year.
So this is a little bit different.
We're not grouping by author in this case.
We have a couple of books that were released in the same year by different authors and this is sort
of arbitrary and very arbitrary.
But how do we calculate the average stock quantity for books released in the same year.
Looks like this select e.g. average stock quantity from books group by release year.
So let's try it.
Select average and we want to stock quantity quantity from books.
GROUP BY released here just like that.
Not that insightful to look at.
Let's be honest.
But maybe we could do something like this.
Let's print out the release year that count how many books were released say you're in an average year.
So it will look like the average stock quantity excuse me so we'll have released year.
And then let's also well let's just leave it at that at least and an average stock quantity.
And if I do that you can see 1945 95 or average quantity hundred 2001 134 is your average quantity.
Yes.
Not that useful.
I totally agree.
But I just want to mix it up because we've been doing a lot of group by author name comma author name
and it gets kind of old so we can group by other important pieces of data.
But of course we could do something like this.
Select Let's do our good old author name author Al name and average Let's do average pages written by
every author or each author from books group by author L. name author F. name.
Ooh boy.
A little bit too eager there.
What's her problem.
Looks like I'm missing a comma.
Right here.
OK.
So you can see the average page is written.
We saw how to select the men in the Macs as well as the sum.
Now we have average.
Also it's important to note that someone like let's see John Steinbeck who we know has one book 181
it still adds the four decimal points.
That has to do with the data type that this is.
And basically I understand punt that one we talk about data types but I just wanted to highlight it
here.
You still get those four decimal points even if it's an even integer even not meaning.
Ok that's a bad choice of words not as an even and odd.
Let's say as a whole number.
All right so that's average.
And that actually wraps up the section on the new content on these aggregate functions.
So we saw count what we saw grouped by and then count min max sum an average all different things that
we can do on their own or in conjunction with Group By.
All right so now we're going to get another chance to practice it.
Hopefully you're looking forward to that.
And if you're not it's still good to do.
It's like you know vegetables just gotta eat them.
I hope I don't offend anyone.
If you're vegetarian right.