# 4.3. Hàm tổng hợp

### <span style="mso-list: Ignore;">4.3.1.<span style="font: 7.0pt 'Times New Roman';"> </span></span>AVG

Tính giá trị trung bình của tất cả các giá trị một trường dữ liệu.

**Cú pháp:**

**AVG** (truong\_du\_lieu\_so Số)<span style="mso-spacerun: yes;"> </span>=&gt; DOUBLE

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol; font-weight: normal; mso-bidi-font-weight: bold;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**truong\_du\_lieu\_so:** Trường dữ liệu cần tính giá trị trung bình với kiểu dữ liệu là DOUBLE, INTEGER, BIGINT, DECIMAL, hoặc FLOAT.

**Ví dụ về AVG:**

```mysql
SELECT AVG(1.5)
-- 1.5

```

**Ví dụ về AVG: cột val\[0.6348, -1.301466\]:**

```mysql
SELECT AVG(“val”)
-- -0.333333

```

**Ví dụ về AVG: với hàm GROUP BY:**

```mysql
SELECT mat_hang, AVG(san_luong)
FROM inet.sample
GROUP BY mat_hang
-- Cà rốt, 3000 
-- Cam sành, 25.25 
-- Ổi, 70 

```

### <span style="mso-list: Ignore;">4.3.2.<span style="font: 7.0pt 'Times New Roman';"> </span></span>COUNT

Đếm tổng số lượng của các giá trị trong trong một trường dữ liệu.

**Cú pháp:**

**COUNT** (Truong\_du\_lieu\_so Số)<span style="mso-spacerun: yes;"> </span>=&gt; BIGINT

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol; font-weight: normal; mso-bidi-font-weight: bold;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>Truong\_du\_lieu\_so: Trường dữ liệu cần đếm với kiểu dữ liệu dạng số.

**Ví dụ về COUNT:**

```mysql
SELECT COUNT(mat_hang)
-- 10

```

**Ví dụ về COUNT: với hàm GROUP BY:**

```mysql
SELECT mat_hang, COUNT(san_luong)
FROM inet.sample
GROUP BY mat_hang
-- Cà rốt, 3 
-- Cam sành, 5 
-- Ổi, 2 

```

### <span style="mso-list: Ignore;">4.3.3.<span style="font: 7.0pt 'Times New Roman';"> </span></span>COUNTDISTINCT

Đếm tổng số lượng của các giá trị trong trong một trường dữ liệu.

**Cú pháp:**

**COUNT** (truong\_du\_lieu\_so Số)<span style="mso-spacerun: yes;"> </span>=&gt; BIGINT

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol; font-weight: normal; mso-bidi-font-weight: bold;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';">  </span></span></span>**truong\_du\_lieu\_so:** Trường dữ liệu cần đếm với kiểu dữ liệu dạng số

**Ví dụ về COUNT: với hàm GROUP BY:**

```mysql
SELECT mat_hang, COUNT(san_luong)
FROM inet.sample
GROUP BY mat_hang
-- Cà rốt, 3 
-- Cam sành, 5 
-- Ổi, 2 

```

### <span style="mso-list: Ignore;">4.3.4.<span style="font: 7.0pt 'Times New Roman';"> </span></span>COUNTEXISTING

### <span style="mso-list: Ignore;">4.3.5.<span style="font: 7.0pt 'Times New Roman';"> </span></span>COUNTMISING

### <span style="mso-list: Ignore;">4.3.6.<span style="font: 7.0pt 'Times New Roman';"> </span></span>FIRST

### <span style="mso-list: Ignore;">4.3.7.<span style="font: 7.0pt 'Times New Roman';"> </span></span>FIRSTQUATILE

### <span style="mso-list: Ignore;">4.3.8.<span style="font: 7.0pt 'Times New Roman';"> </span></span>LAST

### <span style="mso-list: Ignore;">4.3.9.<span style="font: 7.0pt 'Times New Roman';"> </span></span>MAX

Tính giá trị lớn nhất của các giá trị trong một trường dữ liệu.

**Cú pháp:**

**MAX** (truong\_du\_lieu\_so Số)<span style="mso-spacerun: yes;"> </span>=&gt; BIGINT

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol; font-weight: normal; mso-bidi-font-weight: bold;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**truong\_du\_lieu\_so:** Trường dữ liệu cần đếm với kiểu dữ liệu dạng số

**Ví dụ về MAX:**

```mysql
SELECT MAX(san_luong)
-- 300

```

**<span style="font-family: 'Courier New'; color: black; mso-color-alt: windowtext;">Ví dụ về MAX: với hàm GROUP BY:</span>**

```mysql
SELECT mat_hang, MAX(san_luong)
FROM inet.sample
GROUP BY mat_hang
-- Cà rốt, 300 
-- Cam sành, 59 
-- Ổi, 272

```

### <span style="mso-list: Ignore;">4.3.10.</span>MEAN

### <span style="mso-list: Ignore;">4.3.11.</span>MEDIAN

### <span style="mso-list: Ignore;">4.3.12.</span>MIN

Tính giá trị nhỏ nhất của các giá trị trong một trường dữ liệu.

**Cú pháp:**

**MIN** (truong\_du\_lieu\_so Số)<span style="mso-spacerun: yes;"> </span>=&gt; BIGINT

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol; font-weight: normal; mso-bidi-font-weight: bold;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';">  </span></span></span>**truong\_du\_lieu\_so:** Trường dữ liệu cần đếm với kiểu dữ liệu dạng số

**Ví dụ về MIN:**

```mysql
SELECT MIN(san_luong)
-- 10

```

**Ví dụ về MIN: với hàm GROUP BY:**

```mysql
SELECT mat_hang, MIN(san_luong)
FROM inet.sample
GROUP BY mat_hang
-- Cà rốt, 46
-- Cam sành, 10 
-- Ổi, 39

```

### <span style="mso-list: Ignore;">4.3.13.</span>P25TH

### <span style="mso-list: Ignore;">4.3.14.</span>P50TH

### <span style="mso-list: Ignore;">4.3.15.</span>P75TH

### <span style="mso-list: Ignore;">4.3.16.</span>P90TH

### <span style="mso-list: Ignore;">4.3.17.</span>P99TH

### <span style="mso-list: Ignore;">4.3.18.</span>SECONDQUARTILE

### <span style="mso-list: Ignore;">4.3.19.</span>STD

### <span style="mso-list: Ignore;">4.3.20.</span>SUM

Tính tổng của các giá trị trong một trường dữ liệu.

**Cú pháp:**

**SUM** (truong\_du\_lieu\_so Số)<span style="mso-spacerun: yes;"> </span>=&gt; <span style="mso-bidi-font-size: 13.0pt; line-height: 115%;">DOUBLE</span>

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol; font-weight: normal; mso-bidi-font-weight: bold;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**truong\_du\_lieu\_so:** Trường dữ liệu tính tổng đếm với kiểu dữ liệu dạng số.

**<span style="mso-bidi-font-size: 13.0pt; line-height: 115%;">Ví dụ về SUM:</span>**

```mysql
SELECT SUM(san_luong)
-- 10

```

**Ví dụ về SUM: với hàm GROUP BY:**

```mysql
SELECT mat_hang, SUM(san_luong)
FROM inet.sample
GROUP BY mat_hang
-- Cà rốt, 46
-- Cam sành, 10 
-- Ổi, 39

```

### <span style="mso-list: Ignore;">1.1.21.</span>THIRDQUATILE

### <span style="mso-list: Ignore;">1.1.22.</span>VARIANCE