1
00:00.640 --> 00:02.320
So here is the problem.

2
00:02.360 --> 00:07.640
Assume you are given a table containing Amazon purchasing activity.

3
00:08.120 --> 00:12.320
Write a query to calculate the cumulative purchases for each product type.

4
00:12.960 --> 00:15.200
Order chronologically.

5
00:16.720 --> 00:22.440
The output should consist of order, date, product, and the cumulative sum of quantities purchased.

6
00:23.000 --> 00:26.040
So here they have given the total transactions table.

7
00:27.080 --> 00:31.600
So let me create this particular table and insert the data into the same.

8
00:35.640 --> 00:38.320
And now we want cumulative purchases.

9
00:38.720 --> 00:43.840
So for that purpose for each product type right.

10
00:43.840 --> 00:47.640
So over here we can do sum of quantity.

11
00:48.280 --> 00:52.040
We can use the sum of quantity over partition by product type.

12
00:52.040 --> 00:57.280
Because for each product type we want this cumulative purchases in order by.

13
00:58.160 --> 01:00.000
We need to do order date right.

14
01:00.360 --> 01:06.880
Then only it will sort the data based upon the order date for each product type, right.

15
01:08.000 --> 01:10.560
So now if you do this particular.

16
01:12.800 --> 01:14.120
Run this particular query.

17
01:14.120 --> 01:18.640
Then you will get for each product type cumulative purchases.

18
01:19.080 --> 01:22.720
So let me just show you how it works.

19
01:23.720 --> 01:26.440
So select star from.

20
01:31.200 --> 01:31.600
Table.

21
01:31.640 --> 01:32.040
Name.

22
01:34.040 --> 01:34.840
Order by.

23
01:40.040 --> 01:40.600
Order!

24
01:40.600 --> 01:41.040
Date.

25
01:43.480 --> 01:47.840
And also we need to do order by product type.

26
01:47.840 --> 01:48.680
So let me.

27
01:53.840 --> 01:55.280
Do order by product type.

28
01:55.280 --> 01:55.880
So C.

29
01:58.280 --> 02:00.680
And now let me run both of these query.

30
02:00.680 --> 02:03.000
So you will get the perfect idea.

31
02:04.240 --> 02:06.160
So for hair dryer let's see.

32
02:06.200 --> 02:11.760
For hair dryer let me do order by over here for product type also.

33
02:19.600 --> 02:22.120
So C five is there right for hair dryer.

34
02:22.560 --> 02:25.080
Then in the second row 25 is there.

35
02:25.280 --> 02:27.840
So we need to do five plus 25.

36
02:27.840 --> 02:30.040
So it will be 30 right.

37
02:30.040 --> 02:31.000
It will be 30.

38
02:31.040 --> 02:32.200
Now for printer.

39
02:32.640 --> 02:35.720
If you see over here 20 is there and 18 is there.

40
02:35.960 --> 02:38.400
So first row it will be 20.

41
02:38.440 --> 02:41.320
And second row 18 will need to add in 20.

42
02:41.520 --> 02:42.960
So it will be 38.

43
02:43.360 --> 02:45.560
So this is how it works right.

44
02:50.920 --> 02:52.560
So thank you so much.