1
00:00.080 --> 00:02.000
Let's see another SQL problem.

2
00:02.680 --> 00:05.080
Categorize products into price buckets.

3
00:05.480 --> 00:09.600
So below is the problem statement given a table of products with their prices.

4
00:10.160 --> 00:15.760
Write a query to categorize each product into one of four price buckets.

5
00:15.800 --> 00:18.000
So these are the four price buckets are there.

6
00:18.000 --> 00:18.920
We can say right.

7
00:19.560 --> 00:23.600
And this is the create table and insert statement.

8
00:23.880 --> 00:27.600
So let me copy this one and let me ask.

9
00:27.800 --> 00:34.840
I am having below table structure and data.

10
00:37.560 --> 00:38.160
Okay.

11
00:38.920 --> 00:40.040
Now let me.

12
00:47.120 --> 00:50.240
Let me paste my table structure and data over here.

13
00:50.960 --> 00:56.200
So it will format the data into tabular format right.

14
00:57.360 --> 00:57.760
Okay.

15
00:57.800 --> 00:58.880
Now let's see.

16
01:01.200 --> 01:02.900
This is my problem statement.

17
01:02.900 --> 01:03.980
We can say right.

18
01:04.540 --> 01:10.100
So again for this problem statement also we need to write the case statement right.

19
01:11.500 --> 01:13.100
So that we are aware about.

20
01:13.140 --> 01:15.980
Now let us the ChatGPT about the same.

21
01:19.340 --> 01:19.700
Okay.

22
01:19.740 --> 01:20.460
Perfect.

23
01:21.380 --> 01:27.100
So this is perfect use case for case expression in SQL.

24
01:28.180 --> 01:28.740
Okay.

25
01:29.060 --> 01:31.460
Now let me copy this particular code.

26
01:31.460 --> 01:34.500
It has given only one solution okay.

27
01:34.540 --> 01:39.340
You can also use this logic to group products for reporting or analytics.

28
01:41.100 --> 01:41.460
Okay.

29
01:41.500 --> 01:43.420
This is the second thing it has given.

30
01:43.620 --> 01:47.820
So let me first do copy this one.

31
01:48.100 --> 01:48.980
And let's see.

32
01:49.660 --> 01:50.180
So.

33
01:52.540 --> 01:57.100
We can say solution by the.

34
02:00.140 --> 02:01.060
ChatGPT.

35
02:01.340 --> 02:02.900
So see our question.

36
02:03.080 --> 02:06.400
Our solution and ChatGPT solution.

37
02:06.640 --> 02:08.360
Both are almost the same, right?

38
02:08.800 --> 02:09.920
Both are same.

39
02:10.360 --> 02:13.120
So it has written the case statements only.

40
02:13.120 --> 02:13.960
But now what?

41
02:14.000 --> 02:15.040
This one is saying.

42
02:15.320 --> 02:20.640
So let me copy this one as well and let me paste it over here.

43
02:21.560 --> 02:27.800
So for each price category how many number of products are there.

44
02:28.160 --> 02:32.720
It is saying like that it price category means for low.

45
02:32.760 --> 02:35.480
How many number of products are there for median?

46
02:35.520 --> 02:38.280
How many number of products are there for how?

47
02:38.320 --> 02:41.360
How many number of products are there and for premium?

48
02:41.360 --> 02:43.080
How many number of products are there?

49
02:43.480 --> 02:47.600
So for each category it is showing how many number of products are there.

50
02:47.600 --> 02:48.040
Right.

51
02:48.920 --> 02:52.720
So again it has done over here the are derived table.

52
02:53.600 --> 02:57.720
It means select query inside the from clause of the another Select statement.

53
02:58.200 --> 03:06.510
And this price category we can use outside of this query In this derived table, it is given the alias

54
03:06.510 --> 03:12.830
of T, and for each price category we want to find number of products, right.

55
03:13.030 --> 03:15.630
So we have to do group by price category right.

56
03:17.990 --> 03:19.150
That is the correct one.

57
03:21.670 --> 03:27.230
So would you like me to extend this and show the average price per price category as well.

58
03:27.230 --> 03:29.750
So no that is not our requirement as of now.

59
03:30.150 --> 03:31.750
So we do not need that one.

60
03:32.030 --> 03:41.710
So ChatGPT will give you multiple solutions as well as multiple scenario as well right.

61
03:41.910 --> 03:46.750
So over here this scenario it has given by ChatGPT by itself.

62
03:46.790 --> 03:49.270
We haven't asked to ChatGPT.

63
03:49.310 --> 03:49.790
Right.

64
03:52.070 --> 03:59.270
So it is that much of smart enough to generate the scenario from our problem statement in our data sets.

65
03:59.310 --> 03:59.910
Right.

66
04:01.390 --> 04:04.190
So we will see the next question into the next lecture.

67
04:04.190 --> 04:04.790
Thank you.