Next up, we're talking about Avg, avg.
Hang on.
Next up, we're talking about average.
And as you might have guessed, because I've said this for pretty much every video in this section,
it does what it sounds like.
Actually, that's a lie.
It sounds like AVG, but what it does is average data.
So it will some things together and then divide them based off of how many things it 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 I don't
know anything.
The average number of users that are the 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.
Okay.
Well, let's just get back to this.
There are a lot of uses for averages.
There's not a perfect way of getting insight.
I don't want to say that the average is this amazing, all encompassing piece of data, but it can't
be useful anyways.
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 buy.
By now we'll be able to do this pretty quickly and it should serve as 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 AVG average release here from books.
And as you can see, we get 1990 9.7895.
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 section.
We'll 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.
We could also do things like select the average page count from all of our books, which is 348.57,
eight, nine pages.
Okay.
So now let's see how to use it with group B, 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 were released in the same year by different authors.
And this is sort of arbitrary, very arbitrary.
But how do we calculate the average stock quantity for books released in the same year?
Looks like this select avg average stock quantity from books grouped by release year.
So let's try it.
Select average and we want stock quantity quantity from books group by released year.
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.
The count how many books were released that year and then the 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 for at least a year and the average stock quantity.
And if I do that, you can see 1945, 95 is our average quantity.
2134 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 grouped by author L name, comma, author
F name and it gets kind of old so we can group buy other important pieces of data.
But of course we could do something like this.
Select Let's do our good old author f name, author l 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.
Oh, boy.
She's a little bit too eager there.
What's our problem?
Looks like I'm missing a comma.
Right here.
So you can see the average page is written.
We saw how to select the min and the max 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 four decimal points.
And that has to do with the data type that this is.
And basically, I'm just going to punt that one until we talk about data types.
But I just want to highlight it here.
You still get those four decimal points, even if it's an even integer, even not meaning.
That's a bad choice of words, not as in even an odd, let's say, as a whole number.
There we go.
All right.
So that's average.
And that actually wraps up the section on or the new content on these aggregate functions.
So we saw count what we saw grouped by and then count min, max, sum and average all different things
that we can do on their own or in conjunction with Group BI.
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 got to eat them.
I hope I don't offend anyone if you're a vegetarian.
All right.