1 00:00:00,150 --> 00:00:04,710 We have one more of these aggregate functions we're going to cover, which is average. 2 00:00:04,740 --> 00:00:06,120 It's a really useful one. 3 00:00:06,270 --> 00:00:09,600 AVG, which is nice and short for average. 4 00:00:10,020 --> 00:00:16,110 It works in the same way we can find the average across all rows in a data set or we can group and then 5 00:00:16,110 --> 00:00:17,130 find averages. 6 00:00:17,250 --> 00:00:26,310 So to find the average release year across all books, it's as simple as select AVG released year. 7 00:00:27,160 --> 00:00:28,570 From books. 8 00:00:28,960 --> 00:00:34,720 And the average release here is 19 99.789, very close to 2000. 9 00:00:35,770 --> 00:00:41,260 But we could also do find the average number of pages across all the books. 10 00:00:41,860 --> 00:00:43,690 There we are, 362. 11 00:00:44,230 --> 00:00:47,380 Or how about the average stock quantity? 12 00:00:50,460 --> 00:00:54,730 128.9499474 OC. 13 00:00:54,780 --> 00:01:01,410 But of course we can also use group BI and do things like calculate the average stock quantity for books 14 00:01:01,410 --> 00:01:03,420 that have been released in the same year. 15 00:01:03,660 --> 00:01:04,950 So how would we do that? 16 00:01:04,980 --> 00:01:09,880 We would group buy released year and then select the average stock quantity. 17 00:01:09,900 --> 00:01:10,680 Let's try it. 18 00:01:11,190 --> 00:01:13,260 Let's select Released Year. 19 00:01:14,160 --> 00:01:17,610 Average Stock Quantity. 20 00:01:18,370 --> 00:01:23,170 And then from books group by released here. 21 00:01:23,560 --> 00:01:28,750 So we're grouping by the year that the books were released and then we're averaging their stock quantity. 22 00:01:28,750 --> 00:01:35,920 So in 2003, the average stock for those books that were released in that year is 66 2001. 23 00:01:35,920 --> 00:01:37,810 I know there is at least a couple of books. 24 00:01:37,900 --> 00:01:40,090 How would we know exactly how many books? 25 00:01:40,090 --> 00:01:42,790 Well, we can just put the count in as well. 26 00:01:42,820 --> 00:01:45,100 We can count the rows in each group. 27 00:01:45,280 --> 00:01:46,390 Count Star. 28 00:01:47,200 --> 00:01:48,880 So exactly what I thought. 29 00:01:48,910 --> 00:01:49,540 2001. 30 00:01:49,540 --> 00:01:51,910 There was three books released in that year. 31 00:01:51,910 --> 00:01:56,170 The average stock quantity is 134.3333. 32 00:01:56,170 --> 00:01:58,240 And that's all there is to average. 33 00:01:58,240 --> 00:01:59,470 It's a pattern. 34 00:01:59,470 --> 00:02:05,590 Hopefully you can recognize at this point, right some min max average count, you can use them on an 35 00:02:05,590 --> 00:02:11,650 entire table or use them in groups to find out more information about those groups. 36 00:02:11,650 --> 00:02:16,720 You can do a lot of analysis simply by creating different groups, grouping by different aspects of 37 00:02:16,720 --> 00:02:22,360 your data, and then using these different aggregate functions to query and figure out more about those 38 00:02:22,360 --> 00:02:22,990 groups.