Here's our next challenge.
What we're trying to find out is the average rating for each of our TV series that we have.
And then I want it to be sorted or ordered from lowest to highest.
So this will involve a couple of things, right?
We have to have a group buy at some point.
We need to have a join.
We need to have an order buy.
We need to do an average.
And I think that's it.
So we have the title of every show, along with all of the reviews left for that show, grouped together,
averaged and sorted.
Try it if you'd like, and I'll go ahead and do it myself.
So the first thing we want would be basically to start with what we did in the last video where we select
the title and the rating.
Is that all we need?
Title and rating from all of the shows where they match up, where they join together, and then I want
to group them together by title so that I can average the ratings because now I have all of the reviews
left for Archer, all of the ratings for Arrested Development, all of the ones for Freaks and Geeks.
Then I just grouped them together.
So I'll duplicate this.
I'll do it down here group by title, and that will get me part of the way there.
But once I've done that grouping by title, I don't want just rating.
There isn't one rating anymore When we grouped by title for Fargo, well, there's two ratings.
Freaks and Geeks has four ratings, so I want to do the average.
So average call the average function.
Let's see if that works for us.
We're now getting an average we could round this.
We haven't really talked about round, but there is a function called round.
These are a little long, but they're accurate.
The next thing we want to do is sort them from lowest to highest.
So we'll do an order by.
But in order to do an order by, I'm going to give this a name, as we'll call it, average rating.
And I'll do this on separate lines just like that.
Okay, so select title and average rating as average rating grouped by title, and then at the end order
by average rating.
And we want ascending lowest to highest.
So we get General Hospital with its mighty 5.38 all the way up to halt and catch fire with its 9.9 grade
show.
Got to watch that And that is what we were supposed to do, right?
5.38 up to nine nine.
We called it average rating.
We sorted.
That's all good.
Now, I did say we could round this, I didn't in this screenshot, but if we wanted to it looks like
this we round.
That's the name of the function.
Actually, I should just show it to you Here, select round.
How about 3.14159?
If I just try and round it this way, you'll see that it rounds it to the nearest whole number.
So if I had done 3.99, it rounds it up to four.
But if I instead say a second argument, a second value after the thing I'm trying to round, if I say
round two, it rounds it to two digits, 3.14.
And I think two digits is a good number for these ratings.
So we'll do round the average rating to two digits.
This is above and beyond not required, but that's a lot easier to look at and it's just cleaner.
Okay.
Next up, another challenge.