All language subtitles for 1. Introduction to Window functions

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French Download
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:01,030 --> 00:00:04,900 In this section, we will learn about the Windows function. 2 00:00:07,740 --> 00:00:14,700 Now before restarting, let's see how Windows function are different from the functions that we have 3 00:00:14,700 --> 00:00:16,140 already discussed. 4 00:00:17,010 --> 00:00:21,180 Now let's take an example to highlight such differences. 5 00:00:22,020 --> 00:00:25,650 Suppose we have a data of a retail chain. 6 00:00:26,190 --> 00:00:27,720 We have three columns. 7 00:00:27,720 --> 00:00:35,520 We have quarter store and the sales value of that particular store in that particular quarter. 8 00:00:36,560 --> 00:00:44,960 So, for example, in this first row in quarter one, the sales of store A is around 40 units. 9 00:00:46,520 --> 00:00:47,270 No. 10 00:00:47,300 --> 00:00:55,640 If we applied the rule functions that we have discussed, rule functions such as lower upper case or 11 00:00:55,640 --> 00:01:04,820 any mathematical functions such as multiplication, divide, etc. those function will only use the value 12 00:01:04,820 --> 00:01:07,220 of that particular row only. 13 00:01:08,090 --> 00:01:17,210 For example, if we want to multiply the sales value by 0.2 or you can say we are calculating 20% of 14 00:01:17,210 --> 00:01:17,810 the sale. 15 00:01:18,580 --> 00:01:27,730 Then we get this new column where each of this cell is only using the value that is available in that 16 00:01:27,730 --> 00:01:28,750 particular row. 17 00:01:29,380 --> 00:01:37,510 For example, here the sales is 40 units, so point two of that, 40 is eight. 18 00:01:37,540 --> 00:01:40,960 Similarly, for 60, we are getting 12. 19 00:01:41,590 --> 00:01:45,640 And similarly, 0.2 of 100 is 20. 20 00:01:46,520 --> 00:01:54,350 So you can see that we are only using the values that are available in any particular row. 21 00:01:55,890 --> 00:02:03,030 We can't access the values of any other role, for example, in this particular cell. 22 00:02:03,180 --> 00:02:08,810 I wanted the value of some of all the sales values of a story. 23 00:02:09,330 --> 00:02:11,160 I won't be able to do that. 24 00:02:12,960 --> 00:02:21,030 Now, another type of functions that we have discussed are aggregate functions in aggregate function. 25 00:02:21,480 --> 00:02:26,790 We were able to utilize the information available in other roles. 26 00:02:26,940 --> 00:02:37,380 For example, if I group my data by a store and apply the sum aggregate function on sales column, then 27 00:02:37,380 --> 00:02:40,110 I would have got this table. 28 00:02:40,920 --> 00:02:50,070 A store and a total so aggregate functions were able to use the information available in multiple rows. 29 00:02:51,390 --> 00:02:52,840 And role functions. 30 00:02:52,860 --> 00:03:00,090 We were only able to use the information available in that particular row, but in aggregate function 31 00:03:00,090 --> 00:03:05,970 we were able to access the information or data available in multiple rows. 32 00:03:06,660 --> 00:03:11,730 But the drawback of aggregate function is that it will roll up your data. 33 00:03:12,120 --> 00:03:20,130 For example, here I have five rows, but if I use aggregate function, I will get only two rows. 34 00:03:20,960 --> 00:03:28,100 There is no way with these two particular functions to get the aggregated values without rolling up 35 00:03:28,100 --> 00:03:28,850 your data. 36 00:03:29,830 --> 00:03:33,340 The solution to this problem is window function. 37 00:03:34,140 --> 00:03:35,550 In window function. 38 00:03:35,550 --> 00:03:45,540 You can preserve the modularity of your data and you will be able to get the aggregated values or any 39 00:03:45,540 --> 00:03:50,610 other value using the values of other rows of your data. 40 00:03:51,150 --> 00:04:02,010 So for example, if I wanted another column of total in front of each row, I can easily use Windows 41 00:04:02,010 --> 00:04:04,260 function to calculate this column. 42 00:04:05,340 --> 00:04:11,610 So let me repeat once again in the row functions that we have discussed, we can only use the data that 43 00:04:11,610 --> 00:04:13,980 is available in that particular row. 44 00:04:14,400 --> 00:04:22,170 In aggregate function, I can use the data available in multiple rows, but the final result in table 45 00:04:22,170 --> 00:04:24,390 will be a rolled up table. 46 00:04:25,200 --> 00:04:33,270 It will not preserve the number of rows that you have in your original dataset, but with Windows function, 47 00:04:33,270 --> 00:04:37,110 you can utilize the information available in other rows. 48 00:04:38,310 --> 00:04:45,720 And you can also reserve the number of rows or data that you have in your original table. 49 00:04:47,450 --> 00:04:49,640 Now let's see the definition. 50 00:04:52,090 --> 00:04:59,740 So when those function are the functions that provide ability to perform calculation across multiple 51 00:04:59,740 --> 00:05:03,490 rows that are related to your current query row. 52 00:05:04,680 --> 00:05:10,740 And the result of Windows function are calculated using a sliding window frame. 53 00:05:12,480 --> 00:05:20,220 So here our sliding window is this If we are calculating for storage, since we are calculating the 54 00:05:20,220 --> 00:05:23,350 sum of store sales, so the sum is 180. 55 00:05:23,430 --> 00:05:27,150 So for all the store A, we are getting 181 8180. 56 00:05:27,150 --> 00:05:33,690 So this is our sliding window for rows with store B, this will be our sliding window. 57 00:05:35,790 --> 00:05:37,800 And the sum will be 160. 58 00:05:42,080 --> 00:05:50,030 Now, again, I have explained to you how Windows functions are different, so let me repeat once more. 59 00:05:51,600 --> 00:05:58,470 So unlike aggregate function, Windows function does not cause these rules to become grouped into a 60 00:05:58,470 --> 00:05:59,820 single output unit. 61 00:06:00,180 --> 00:06:06,270 So as I have mentioned, you, if you are using aggregate function, all your rules will be grouped 62 00:06:06,270 --> 00:06:07,830 into a single row. 63 00:06:08,190 --> 00:06:15,240 But if you are using windows function, the rows will not be grouped and you will get the aggregated 64 00:06:15,240 --> 00:06:19,020 value depending on the rows values of multiple rows. 65 00:06:20,050 --> 00:06:26,200 And as I have mentioned earlier, Windows functions have access not just to the current row but to the 66 00:06:26,200 --> 00:06:28,870 multiple rows in the sliding window. 67 00:06:31,670 --> 00:06:34,490 Now let's look at the syntax of Windows function. 68 00:06:35,100 --> 00:06:38,790 So the syntax is window function. 69 00:06:38,970 --> 00:06:42,900 You have to mention the window function name you want to apply. 70 00:06:43,470 --> 00:06:45,900 Then you have to write over. 71 00:06:45,900 --> 00:06:47,790 Over is a keyword over here. 72 00:06:48,090 --> 00:06:52,890 And in bracket you have to write partition by and order by. 73 00:06:53,580 --> 00:07:02,800 In front of partition by you have to write the column on which you want grouping and in the order by 74 00:07:02,910 --> 00:07:08,520 you have to write the column name on which you want the ordering. 75 00:07:09,780 --> 00:07:11,700 Now let's take an example. 76 00:07:11,940 --> 00:07:15,930 Suppose in the first column we have customers. 77 00:07:15,930 --> 00:07:18,540 In the second column we have estate. 78 00:07:18,660 --> 00:07:25,680 And in the third column we have the number of orders each one of this customer have placed. 79 00:07:27,020 --> 00:07:35,060 Now suppose we want to rank our customers in each state depending on the number of orders they have 80 00:07:35,060 --> 00:07:35,780 placed. 81 00:07:36,530 --> 00:07:41,690 The syntax will be this only here the window function is row number. 82 00:07:42,260 --> 00:07:49,730 Don't worry, we will discuss all the window functions that are available in more detail in our later 83 00:07:49,730 --> 00:07:50,600 lectures. 84 00:07:51,420 --> 00:07:58,260 But here I just wanted to show you how the syntax looked like in a real life situation. 85 00:07:58,650 --> 00:08:00,790 So the window function is row number. 86 00:08:00,810 --> 00:08:07,470 Then there is this keyword over, and in the bracket we want to write the partition by and order by. 87 00:08:08,740 --> 00:08:17,320 So since we want the top customer from each estate, we will be grouping our data on a state column. 88 00:08:17,380 --> 00:08:26,980 So we have to write partition by state and then we want to give rank as one to the customer with the 89 00:08:26,980 --> 00:08:28,720 most number of orders. 90 00:08:30,040 --> 00:08:38,620 So in order buy, we will write the orders or the number of orders if the column name is number orders. 91 00:08:39,320 --> 00:08:47,870 So in order why we have to write orders and then just like other order statements, you have to write 92 00:08:47,870 --> 00:08:50,270 ascending or descending with the column. 93 00:08:50,270 --> 00:08:54,440 So here I want to order my data in descending order. 94 00:08:54,650 --> 00:08:59,600 So partition by state and order by number of orders. 95 00:09:01,130 --> 00:09:04,790 The resultant column, which I will get is this. 96 00:09:06,110 --> 00:09:15,920 You can see that my data is grouped by stores and the ranking is done on the basis of number of orders 97 00:09:15,920 --> 00:09:17,330 in the descending order. 98 00:09:18,940 --> 00:09:20,830 So Customer C five. 99 00:09:21,620 --> 00:09:29,240 And store a with maximum number of orders will get a value of one in this new column. 100 00:09:29,930 --> 00:09:32,780 C seven customer will get a value of two. 101 00:09:32,780 --> 00:09:36,110 See one customer will get a value of three. 102 00:09:36,950 --> 00:09:39,500 And similarly, the ranking is start. 103 00:09:40,130 --> 00:09:43,940 If we change the estate or store. 104 00:09:44,740 --> 00:09:51,370 So you will find partition by and order by used in each window. 105 00:09:51,370 --> 00:09:56,140 Function will discuss more about this in our later videos. 10583

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.