The next aggregate function will look at is some sum, will sum up some values together.
It works in the same way that all the other aggregate functions we've looked at will work.
We can operate on the entire table.
For example, we could select the sum of all the pages in the entire table, the page count from books,
and there are 7257 pages.
If we sum up all of them in the in the entire table.
But I can also operate with groups.
So I can do something like sum with group by to sum all the pages each author has written.
So I would select.
I don't know how about the author?
Let's just do last name.
Let's ignore the fact that Harris is in there twice with two different heresies just to keep the group
by shorter select author, last name and the sum of the pages they've written from books grouped by
author last name.
And we see Lahiri has written 489 books, game books, pages in our database.
GAIMAN 977.
EGGERS 1293 And that makes sense, I think.
Let's verify.
Select let's do author L name comma pages from books for all the books.
And we'll see.
EGGERS We had, what, 352 plus 500, so there's 850.
And then another Eggers book down here is 437.
So 850 plus 437 ish is going to give us 1293.
Lahiri 489 Well, she has a book that's 291 pages, 198 You add them together and we get 489 and if
you weren't sure, we could use a SQL as a really janky calculator.
291 plus and then her other book, 198 and we get 489 and that's exactly what we see.
So that's one way of using group by with some for this data set, we could even do something else like
sum up the release years for a given author or yeah, sure, we'll do that.
It doesn't really make any sense to do that, but let's try it.
Let's select.
Author, last name, and then let's select the count of how many books they've written.
And then the some of release year.
From books grouped by author last name, and it's released with a DH year.
My bed.
All right.
Does it make any sense to do this?
I would say no, but we can.
Lahiri has two books, and the total of their released years is 3999.
I think that's enough of this example.
We're running out of things that make rational sense to do.
But I just wanted to show you at least two examples of using some with group by.
So some will sum up all of the values that we provide.
And in this case, it's all the released years for a given group where the groups are formed by author
last name.
I guess I should ask you a question.
What do you think will happen if I do this?
Select sum of what if we sum up all the author last names?
It's not numbers.
What happens from books.
We don't get concatenation.
It doesn't do like Lahiri, Gaiman and all the authors.
It doesn't shove them together.
It just treats them as zero.
They are not numbers, so it sums them up to be zero.
So just get to know what happens there.