All right, next up here.
This one will be nice and short.
All we're trying to figure out is how many times does the average user post.
So we have a board or our investors want to know basically what our engagement is like just in general.
For every user, Any user.
How many times can we assume they've posted?
So this is just across the board and really all we need to do is take the total number of Post's photos
and divide it by the total number of users.
And you could do that separately in different lines, or you could do a big joint statement between
users and photos and then use average and calculate average.
But you could just do it using sub queries, which is what I'm going to do.
So something a little different.
So we'll just do calculate.
The average number of photos per user.
So what we're looking for is total number of photos divided by total number of users.
And the first part, each of those parts individually we know how to do.
We can just do a select count star from photos, and that will give us the total number of photos.
If I had a semicolon, 257 and then four users, I just need to change that to be users.
Select count from users and we get 100.
Now, if you're good at mental math, even if you're not, it's easy to figure out our average in your
head.
But of course we're trying to do this dynamically so that if we have X 10,000 more users tomorrow,
this still applies.
So using sub queries, basically what I can do is divide these two.
So I can't just do this.
I'll get a syntax error.
What we need to do, like we've seen before with sub queries is add parentheses around these two things.
But even that won't be enough.
What are we missing?
Well, it's just like we can't just say five plus five or we can't just do one divided by two.
We have to say select one divided by two in order to get anything.
So we need an extra select up here.
Yeah, it's kind of a mess.
You know, we could do this on separate lines, maybe.
I'm not actually sure how to best format this because it's kind of a weird query, but maybe something
like this.
Well, we can leave it at that for now and I'll get rid of or I'll comment that out.
Now, if we run this.
Well, we get this massive line here, but 2.57.
So every user has 2.5.
On average, every user has 2.57 posts.
That's thrown off significantly for a couple of reasons We'll see later.
There are bots and users who just don't post anything, and if we tried to get rid of these bots, our
average would change.
So we'll get there in a moment.
What we could do is just add in simple alias, we'll just call it as average avg.
And there we go.
So that's the answer to that one.
If you came up with another way, feel free to share it and we'll talk about it in the comments.
All right.
Moving on.