We have one more of these aggregate functions we're going to cover, which is average.
It's a really useful one.
AVG, which is nice and short for average.
It works in the same way we can find the average across all rows in a data set or we can group and then
find averages.
So to find the average release year across all books, it's as simple as select AVG released year.
From books.
And the average release here is 19 99.789, very close to 2000.
But we could also do find the average number of pages across all the books.
There we are, 362.
Or how about the average stock quantity?
128.9499474 OC.
But of course we can also use group BI and do things like calculate the average stock quantity for books
that have been released in the same year.
So how would we do that?
We would group buy released year and then select the average stock quantity.
Let's try it.
Let's select Released Year.
Average Stock Quantity.
And then from books group by released here.
So we're grouping by the year that the books were released and then we're averaging their stock quantity.
So in 2003, the average stock for those books that were released in that year is 66 2001.
I know there is at least a couple of books.
How would we know exactly how many books?
Well, we can just put the count in as well.
We can count the rows in each group.
Count Star.
So exactly what I thought.
2001.
There was three books released in that year.
The average stock quantity is 134.3333.
And that's all there is to average.
It's a pattern.
Hopefully you can recognize at this point, right some min max average count, you can use them on an
entire table or use them in groups to find out more information about those groups.
You can do a lot of analysis simply by creating different groups, grouping by different aspects of
your data, and then using these different aggregate functions to query and figure out more about those
groups.