Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
0
1
00:00:06,912 --> 00:00:12,288
Now, we will be discussing some of the aggregate functions such as count, sum, average
1
2
00:00:12,544 --> 00:00:13,568
Min and max
2
3
00:00:14,336 --> 00:00:15,616
First is the count function
3
4
00:00:16,128 --> 00:00:19,712
Count function will return the count of the expression that you have mentioned
4
5
00:00:21,248 --> 00:00:25,344
For example if you want to find out the number of sales that you have done
5
6
00:00:25,600 --> 00:00:31,744
You can count the number of sales lines that you have, to get the total number of sales that you are done
6
7
00:00:32,256 --> 00:00:36,352
Or you want to find out the count of customers with name starting with A
7
8
00:00:36,608 --> 00:00:38,400
Then again count function will help you
8
9
00:00:38,656 --> 00:00:40,448
The syntax of count function is
9
10
00:00:40,704 --> 00:00:42,752
You select the column names if you want
10
11
00:00:43,008 --> 00:00:46,848
Count will be written as count and then you give the column name
11
12
00:00:47,104 --> 00:00:49,664
Of the column of which you want the
12
13
00:00:49,920 --> 00:00:50,432
Count
13
14
00:00:51,200 --> 00:00:55,296
So it will count number of non null values in that column
14
15
00:00:56,576 --> 00:01:01,184
After it has applied the condition so if you are mentioned any where clause
15
16
00:01:01,440 --> 00:01:03,232
It will check the condition
16
17
00:01:03,488 --> 00:01:08,608
And after that if there is any non null value in that particular column which were mentioned after the count
17
18
00:01:08,864 --> 00:01:10,912
It will give that particular count
18
19
00:01:12,192 --> 00:01:15,008
Let's look at some of the examples to understand this
19
20
00:01:17,056 --> 00:01:21,152
So this first example where I have returned select count star from sales
20
21
00:01:21,664 --> 00:01:22,176
It will
21
22
00:01:22,432 --> 00:01:23,712
Go to the sales table
22
23
00:01:23,968 --> 00:01:24,736
And it will
23
24
00:01:24,992 --> 00:01:26,272
Look at all the records
24
25
00:01:27,296 --> 00:01:31,904
And it will give back the count of all the rows in that particular table
25
26
00:01:32,672 --> 00:01:35,488
Let it go and write this in the PG admin interface
26
27
00:01:36,000 --> 00:01:37,280
Select
27
28
00:01:38,560 --> 00:01:39,584
Count star
28
29
00:01:43,424 --> 00:01:45,728
Remember that I put the star
29
30
00:01:45,984 --> 00:01:47,008
Within the bracket
30
31
00:01:47,264 --> 00:01:53,408
Whatever column name you want to mention you have to put it into bracket, from sales, sales is the table name
31
32
00:01:53,664 --> 00:01:54,176
When I run this
32
33
00:01:54,688 --> 00:01:56,736
I get a count of
33
34
00:01:57,760 --> 00:01:59,552
9994
34
35
00:02:00,576 --> 00:02:05,184
This is the total count but if you notice the column name is written as count
35
36
00:02:05,952 --> 00:02:11,072
This may not make any sense to anyone who looks at this count that is why we will be using aliases
36
37
00:02:11,584 --> 00:02:12,608
And mention
37
38
00:02:12,864 --> 00:02:14,400
Count star as
38
39
00:02:14,912 --> 00:02:17,472
The total count of sales something like that
39
40
00:02:17,984 --> 00:02:19,776
So that we get the right column name
40
41
00:02:22,592 --> 00:02:24,896
Now, Imagine if you want to find out
41
42
00:02:25,408 --> 00:02:28,736
How many orders that particular customer has given
42
43
00:02:28,992 --> 00:02:32,320
And how many products that particular customer has ordered
43
44
00:02:33,088 --> 00:02:34,880
Go and look at the
44
45
00:02:35,136 --> 00:02:36,160
Sales table
45
46
00:02:36,416 --> 00:02:40,000
By just doing select star from sales
46
47
00:02:44,352 --> 00:02:49,728
So for example, this first customer with customer ID CG 12520
47
48
00:02:50,752 --> 00:02:55,360
It has two entries on the top those two entries have the same order ID
48
49
00:02:55,616 --> 00:02:57,920
Which means it was one single order
49
50
00:02:58,176 --> 00:03:02,784
In which two different products were ordered so the product ID in both these
50
51
00:03:03,040 --> 00:03:04,320
Two rows is different
51
52
00:03:05,600 --> 00:03:07,136
If I want to find out
52
53
00:03:07,392 --> 00:03:10,976
Count of all the orders that this particular customer has given
53
54
00:03:11,232 --> 00:03:15,328
And the count of different products that this customer has ordered
54
55
00:03:15,584 --> 00:03:16,608
I start typing
55
56
00:03:17,120 --> 00:03:18,144
Select
56
57
00:03:20,448 --> 00:03:23,520
And select the count of
57
58
00:03:23,776 --> 00:03:25,056
Order lines
58
59
00:03:31,456 --> 00:03:37,600
So each separate order line is giving me the number of products that that particular customer has ordered
59
60
00:03:37,856 --> 00:03:38,624
So I Name this as
60
61
00:03:39,136 --> 00:03:44,768
Number of products ordered
61
62
00:03:47,584 --> 00:03:49,632
Then I'll find out
62
63
00:03:52,704 --> 00:03:53,728
Count of
63
64
00:03:54,240 --> 00:03:56,032
Order IDs
64
65
00:03:56,288 --> 00:03:57,824
Distinct order ID
65
66
00:04:03,968 --> 00:04:06,272
If I do not write distinct
66
67
00:04:08,064 --> 00:04:10,880
Repetitive order IDS will be
67
68
00:04:11,136 --> 00:04:12,416
Will be counted multiple Times
68
69
00:04:12,672 --> 00:04:18,815
As number of orders
69
70
00:04:22,143 --> 00:04:22,911
And
70
71
00:04:23,167 --> 00:04:26,751
This will be from the table
71
72
00:04:27,007 --> 00:04:29,311
Sales
72
73
00:04:29,567 --> 00:04:32,383
Where customer ID
73
74
00:04:32,639 --> 00:04:38,783
Will be this CG 12520
74
75
00:04:39,039 --> 00:04:39,551
CG12520
75
76
00:04:40,063 --> 00:04:42,111
CG12520
76
77
00:04:43,391 --> 00:04:46,207
Select this query and run it
77
78
00:04:49,279 --> 00:04:50,047
You can see
78
79
00:04:50,303 --> 00:04:51,839
The column names are the ones
79
80
00:04:52,095 --> 00:04:53,119
That we provided
80
81
00:04:53,631 --> 00:04:54,143
And
81
82
00:04:54,399 --> 00:04:55,679
This particular customer
82
83
00:04:56,447 --> 00:04:57,727
Ordered three times
83
84
00:04:57,983 --> 00:04:59,263
He gave three orders
84
85
00:04:59,775 --> 00:05:00,287
But
85
86
00:05:00,799 --> 00:05:04,383
One or more of the orders has multiple products in it so
86
87
00:05:04,639 --> 00:05:07,199
Total number of products ordered by this customer is 5
87
88
00:05:08,735 --> 00:05:10,783
Next we'll look at how to use
88
89
00:05:11,295 --> 00:05:12,063
Sum function
6937
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.