1 00:00:00,180 --> 00:00:06,310 The next aggregate function will look at is some sum, will sum up some values together. 2 00:00:06,330 --> 00:00:10,150 It works in the same way that all the other aggregate functions we've looked at will work. 3 00:00:10,170 --> 00:00:12,570 We can operate on the entire table. 4 00:00:12,600 --> 00:00:22,020 For example, we could select the sum of all the pages in the entire table, the page count from books, 5 00:00:22,260 --> 00:00:25,840 and there are 7257 pages. 6 00:00:25,860 --> 00:00:28,950 If we sum up all of them in the in the entire table. 7 00:00:29,160 --> 00:00:32,340 But I can also operate with groups. 8 00:00:32,700 --> 00:00:39,240 So I can do something like sum with group by to sum all the pages each author has written. 9 00:00:39,750 --> 00:00:41,330 So I would select. 10 00:00:41,340 --> 00:00:42,920 I don't know how about the author? 11 00:00:42,930 --> 00:00:44,460 Let's just do last name. 12 00:00:44,460 --> 00:00:50,430 Let's ignore the fact that Harris is in there twice with two different heresies just to keep the group 13 00:00:50,430 --> 00:00:59,880 by shorter select author, last name and the sum of the pages they've written from books grouped by 14 00:01:00,330 --> 00:01:01,800 author last name. 15 00:01:02,840 --> 00:01:10,250 And we see Lahiri has written 489 books, game books, pages in our database. 16 00:01:10,280 --> 00:01:12,020 GAIMAN 977. 17 00:01:12,020 --> 00:01:15,550 EGGERS 1293 And that makes sense, I think. 18 00:01:15,560 --> 00:01:16,520 Let's verify. 19 00:01:16,550 --> 00:01:22,700 Select let's do author L name comma pages from books for all the books. 20 00:01:22,700 --> 00:01:23,730 And we'll see. 21 00:01:23,750 --> 00:01:28,070 EGGERS We had, what, 352 plus 500, so there's 850. 22 00:01:28,070 --> 00:01:31,580 And then another Eggers book down here is 437. 23 00:01:31,580 --> 00:01:36,350 So 850 plus 437 ish is going to give us 1293. 24 00:01:36,530 --> 00:01:45,470 Lahiri 489 Well, she has a book that's 291 pages, 198 You add them together and we get 489 and if 25 00:01:45,470 --> 00:01:50,000 you weren't sure, we could use a SQL as a really janky calculator. 26 00:01:50,000 --> 00:01:58,760 291 plus and then her other book, 198 and we get 489 and that's exactly what we see. 27 00:01:59,120 --> 00:02:06,170 So that's one way of using group by with some for this data set, we could even do something else like 28 00:02:06,530 --> 00:02:13,340 sum up the release years for a given author or yeah, sure, we'll do that. 29 00:02:13,340 --> 00:02:16,250 It doesn't really make any sense to do that, but let's try it. 30 00:02:16,250 --> 00:02:17,540 Let's select. 31 00:02:18,740 --> 00:02:25,310 Author, last name, and then let's select the count of how many books they've written. 32 00:02:25,960 --> 00:02:30,250 And then the some of release year. 33 00:02:30,950 --> 00:02:40,070 From books grouped by author last name, and it's released with a DH year. 34 00:02:40,100 --> 00:02:40,760 My bed. 35 00:02:42,670 --> 00:02:42,970 All right. 36 00:02:42,970 --> 00:02:44,360 Does it make any sense to do this? 37 00:02:44,380 --> 00:02:46,900 I would say no, but we can. 38 00:02:46,900 --> 00:02:51,770 Lahiri has two books, and the total of their released years is 3999. 39 00:02:53,020 --> 00:02:54,980 I think that's enough of this example. 40 00:02:55,000 --> 00:02:57,940 We're running out of things that make rational sense to do. 41 00:02:57,940 --> 00:03:02,710 But I just wanted to show you at least two examples of using some with group by. 42 00:03:02,800 --> 00:03:07,300 So some will sum up all of the values that we provide. 43 00:03:07,300 --> 00:03:12,700 And in this case, it's all the released years for a given group where the groups are formed by author 44 00:03:12,700 --> 00:03:13,450 last name. 45 00:03:14,140 --> 00:03:16,540 I guess I should ask you a question. 46 00:03:16,540 --> 00:03:18,460 What do you think will happen if I do this? 47 00:03:18,460 --> 00:03:24,040 Select sum of what if we sum up all the author last names? 48 00:03:25,620 --> 00:03:26,790 It's not numbers. 49 00:03:26,790 --> 00:03:28,860 What happens from books. 50 00:03:29,900 --> 00:03:31,820 We don't get concatenation. 51 00:03:31,820 --> 00:03:36,350 It doesn't do like Lahiri, Gaiman and all the authors. 52 00:03:36,350 --> 00:03:37,640 It doesn't shove them together. 53 00:03:37,640 --> 00:03:39,860 It just treats them as zero. 54 00:03:39,890 --> 00:03:43,460 They are not numbers, so it sums them up to be zero. 55 00:03:43,790 --> 00:03:45,530 So just get to know what happens there.