Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Now, in the last lecture we discussed about the sum function, or you can say total function.
Now there is another variation of this function.
Through which you can find the running total.
Now, what is running total?
So suppose for see when you have three kinds of order with revenue, 100, 203 hundred.
Now, if you calculate the total, the total will be 600.
But a running total will only add that value and only the values that are above that value.
For example, here in the first row, the revenue is 100.
There is nothing above it, so it will only give 100.
But in the second row the revenue is 200 and there is a revenue of 100 before that.
So the total will be 300 for the third row.
The revenue is 300 and there is already a revenue of 201 hundred above that.
So the running total will be 600.
So running total is calculating the sum up to that point.
Usually running totals are calculated on date values.
For example, you may have heard of terms like year till date or month till date.
Which correspond to total number of sales till that day.
So running total is very useful when we are working with revenues and sales figures.
Now how to calculate running total.
You can do that just by adding order by and to your some function.
So earlier we were only using partition by if we write order by statement as well, the sum function
will calculate the running total.
So when we are finding total sum, we just have to use partition by and it will calculate the total
sum.
If you want to calculate the running total, just add order by with your sum function.
So here in this case, I want my running total to be calculated according to the date.
So you just have to mention ordered by end date.
Now let's go back to our PG admin.
So here in our previous example, we calculated the total sales of each estate.
Now let's calculate the running total of each estate according to the order of date.
The formula will remain the same.
So I will just copy paste it here and then.
And then I'll write some of.
Sales.
Over the partition by will remain the same.
And this time we want to calculate running total according to the order of the order date.
Order by the column name is Order date.
We are using a year of running total year.
If I run this so you will see the difference.
Currently we are only getting total.
I have to put.
When the score.
Let's run this.
You can see that now we are getting the running total.
Our data is ordered by date.
So first we have the Alabama state, for which we have all the orders and the ascending order of order
date.
So this is the order of June 2014.
This the order of May 2014.
Again, you can see that the data is arranged in the ascending order of order date.
Now here we have the running total in the last column.
You can see that for the first order, the sales value was 152.
So the running total is 152.
That is some till this row.
For the second row, the sales is 180.
And the running total is 333.
That is 183.93 plus one 52.64.
So this is the sum of these two values.
Similarly, 1053 is the sum of these three values.
1555 is the sum of these four values and so on.
This will go on till we reach the last value of Alabama.
So if I come here So this is the last value.
Just before that, the running total was 31034.
In the next row, the value was 4.36.
So the running total in the last value is 31038, which is equal to the total value of the sales.
So if you sum all the values till here, this is the sum.
You can also see that in the sales total we are getting the same value.
So running total will calculate the total step by step.
Now.
After Alabama.
We have the data of Arizona State here since we have used partition by state.
The running total will start from zero and it will calculate the running total.
As we have discussed previously and for the last value of Arizona.
Also, the total will be equal to the sales total that we are getting in this column.
You can see that for the last value, the total and the running total is same.
So that's the variation of some function with or without order keyword.
If you use order, you will get the same value in your partition and that will be the total value.
If you are using order by in your sum function, then you will get the running total.
As we have seen here.
That's all for this video.
Thank you.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.