# Chương 4. CÁC HÀM CHỨC NĂNG



# 4.1. Hàm thời gian

### <span style="mso-list: Ignore;">4.1.1.<span style="font: 7.0pt 'Times New Roman';"> </span></span>ADD\_SECOND

Thêm một khoảng thời gian (tính bằng giây) vào một trường dữ liệu ngày tháng.

**Cú pháp:**

**ADD\_SECOND** (truong\_du\_lieu\_thoi\_gian **DATETIME**, gia tri *INT*) =&gt; *DATETIME*

<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\_thoi\_gian**: Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

<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>**gia\_tri:** Số giây cần thêm.

**Ví dụ:**

```mysql
SELECT ADD_SECOND(’15-08-2019 10:01:30’,30)
-- 15-08-2019 10:02:00

```

### <span style="mso-list: Ignore;">4.1.2.<span style="font: 7.0pt 'Times New Roman';"> </span></span>ADD\_MINUTE

Thêm một khoảng thời gian (tính bằng phút) vào một trường dữ liệu ngày tháng.

**Cú pháp:**

**ADD\_MINUTE** (truong\_du\_lieu\_thoi\_gian DATETIME, gia tri INT) =&gt; DATETIME

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

<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>**gia\_tri:** Số phút cần thêm.

**Ví dụ:**

```mysql
SELECT ADD_MINUTE(’15-08-2019 10:01:30’,30)
```

### <span style="mso-list: Ignore;">4.1.3.<span style="font: 7.0pt 'Times New Roman';"> </span></span>ADD\_HOUR

Thêm một khoảng thời gian (tính bằng giờ) vào một trường dữ liệu ngày tháng.

**Cú pháp:**

**ADD\_HOUR** (truong\_du\_lieu\_thoi\_gian DATETIME, gia tri INT) =&gt; DATETIME

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

<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>**gia\_tri:** Số giờ cần thêm.

**Ví dụ:**

```mysql
SELECT ADD_HOUR(’15-08-2019 10:01:30’,5)
-- 15-08-2019 15:01:30
```

### <span style="mso-list: Ignore;">4.1.4.<span style="font: 7.0pt 'Times New Roman';"> </span></span>ADD\_DAY

Thêm một khoảng thời gian (tính bằng ngày) vào một trường dữ liệu ngày tháng.

**Cú pháp:**

**ADD\_DAY** (truong\_du\_lieu\_thoi\_gian DATETIME, gia tri INT) =&gt; DATETIME

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

<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>**gia\_tri:** Số ngày cần thêm.

**Ví dụ:**

```mysql
SELECT ADD_DAY(’15-08-2019 10:01:30’,30)
-- 15-08-2019 10:01:30
```

### <span style="mso-list: Ignore;">4.1.5.<span style="font: 7.0pt 'Times New Roman';"> </span></span>ADD\_WEAK

Thêm một khoảng thời gian (tính bằng tuần) vào một trường dữ liệu ngày tháng.

**Cú pháp:**

**ADD\_WEAK** (truong\_du\_lieu\_thoi\_gian DATETIME, gia tri INT) =&gt; DATETIME

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

<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>**gia\_tri:** Số tuần cần thêm.

**Ví dụ:**

```mysql
SELECT ADD_WEAK(’15-08-2019 10:01:30’,30)
-- 15-08-2019 10:02:00
```

### <span style="mso-list: Ignore;">4.1.6.<span style="font: 7.0pt 'Times New Roman';"> </span></span>ADD\_MONTH

Thêm một khoảng thời gian (tính bằng tháng) vào một trường dữ liệu ngày tháng.

**Cú pháp:**

**ADD\_MONTH** (truong\_du\_lieu\_thoi\_gian DATETIME, gia tri INT) =&gt; DATETIME

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

<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>**gia\_tri:** Số tháng cần thêm.

**Ví dụ:**

```mysql
SELECT ADD_MONTH(’15-08-2019 10:01:30’,6)
-- 15-12-2019 10:01:30

```

### <span style="mso-list: Ignore;">4.1.7.<span style="font: 7.0pt 'Times New Roman';"> </span></span>ADD\_QUARTER

Thêm một khoảng thời gian (tính bằng quý) vào một trường dữ liệu ngày tháng.

**Cú pháp:**

**ADD\_QUARTER** (truong\_du\_lieu\_thoi\_gian DATETIME, gia\_tri INT) =&gt; DATETIME

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

<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>**gia\_tri:** Số quý cần thêm.

**Ví dụ:**

```mysql
SELECT ADD_QUARTER(’15-08-2019 10:01:30’,1)
-- 15-11-2019 10:01:30
```

### <span style="mso-list: Ignore;">4.1.8.<span style="font: 7.0pt 'Times New Roman';"> </span></span>ADD\_YEAR

Thêm một khoảng thời gian (tính bằng năm) vào một trường dữ liệu ngày tháng.

**Cú pháp:**

**ADD\_YEAR** (truong\_du\_lieu\_thoi\_gian DATETIME, gia tri INT) =&gt; DATETIME

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

<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>**gia\_tri:** Số năm cần thêm.

**Ví dụ:**

```mysql
SELECT ADD_YEAR(’15-08-2019 10:01:30’,5)
-- 15-08-2024 10:01:30

```

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

Trả về giá trị giây(từ 0 -59) trong trường dữ liệu thời gian.

**Cú pháp:**

**SECOND** (truong\_du\_lieu\_thoi\_gian DATETIME) =&gt; INT

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

**Ví dụ:**

```mysql
SELECT SECOND(’15-08-2019 10:01:30’)
-- 30

```

### <span style="mso-list: Ignore;">4.1.10. </span>MINUTE

Trả về giá trị phút (từ 0 -59) trong trường dữ liệu thời gian.

**Cú pháp:**

**MINUTE** (truong\_du\_lieu\_thoi\_gian DATETIME) =&gt; INT

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

**Ví dụ:**

```mysql
SELECT MINUTE(’15-08-2019 10:01:30’)
-- 1

```

### <span style="mso-list: Ignore;">4.1.11. </span>HOUR

Trả về giá trị giờ (từ 0- 23) trong trường dữ liệu thời gian.

**Cú pháp:**

**HOUR** (truong\_du\_lieu\_thoi\_gian DATETIME) =&gt; INT

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

**Ví dụ:**

```mysql
SELECT HOUR(’15-08-2019 10:01:30’)
-- 10

```

### <span style="mso-list: Ignore;">4.1.12. </span>DAY

Trả về giá trị ngày (từ 1- 31) trong trường dữ liệu thời gian.

**Cú pháp:**

**DAY** (truong\_du\_lieu\_thoi\_gian DATETIME) =&gt; INT

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

**Ví dụ:**

```mysql
SELECT DAY(’15-08-2019 10:01:30’)
-- 15

```

### <span style="mso-list: Ignore;">4.1.13. </span>MONTH

Trả về giá trị tháng (từ 1- 12) trong trường dữ liệu thời gian.

**Cú pháp:**

**MONTH** (truong\_du\_lieu\_thoi\_gian DATETIME) =&gt; INT

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

**Ví dụ:**

```mysql
SELECT SECOND(’15-08-2019 10:01:30’)
-- 8

```

### <span style="mso-list: Ignore;">4.1.14. </span>QUARTER

Trả về giá trị quý (từ 1- 4) trong trường dữ liệu thời gian.

**Cú pháp:**

**QUARTER** (truong\_du\_lieu\_thoi\_gian DATETIME) =&gt; INT

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

**Ví dụ:**

```mysql
SELECT QUARTER(’15-08-2019 10:01:30’)
-- 3
```

### <span style="mso-list: Ignore;">4.1.15. </span>YEAR

Trả về giá trị năm trong trường dữ liệu thời gian.

**Cú pháp:**

**YEAR** (truong\_du\_lieu\_thoi\_gian DATETIME) =&gt; INT

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

**Ví dụ:**

```mysql
SELECT YEAR(’15-08-2019 10:01:30’)
-- 2019
```

### <span style="mso-list: Ignore;">4.1.16. </span>LASTDAY

Trả về ngày cuối cùng trong tháng với trường dữ liệu thời gian.

**Cú pháp:**

**LASTDAY** (truong\_du\_lieu\_thoi\_gian DATETIME) =&gt; DATETIME

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

**Ví dụ:**

```mysql
SELECT LASTDAY(’15-08-2019 10:01:30’)
-- 31-08-2019 10:01:30
```

### <span style="mso-list: Ignore;">4.1.17. </span>TRUNC\_SECOND

Trả về giá trị thời gian với độ chính xác được tính theo giây.

**Cú pháp:**

**TRUNC\_SECOND** (truong\_du\_lieu\_thoi\_gian DATETIME)<span style="mso-spacerun: yes;"> </span>=&gt; INT

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

**Ví dụ:**

```mysql
SELECT TRUNC_SECOND(’15-08-2019 10:01:30’)
-- 15-08-2019 10:01:30

```

### <span style="mso-list: Ignore;">4.1.18. </span>TRUNC\_MINUTE

Trả về giá trị thời gian với độ chính xác được tính theo phút.

**Cú pháp:**

<span style="mso-spacerun: yes;"> </span>**TRUNC\_ MINUTE** (truong\_du\_lieu\_thoi\_gian)<span style="mso-spacerun: yes;"> </span>=&gt; DATETIME

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

**Ví dụ:**

```mysql
SELECT TRUNC_ MINUTE(’15-08-2019 10:01:30’)
-- 15-08-2019 10:01:00
```

### <span style="mso-list: Ignore;">4.1.19. </span>TRUNC\_HOUR

Trả về giá trị thời gian với độ chính xác được tính theo giờ.

**Cú pháp:**

<span style="mso-spacerun: yes;"> </span>**TRUNC\_HOUR** (truong\_du\_lieu\_thoi\_gian DATETIME)<span style="mso-spacerun: yes;"> </span>=&gt; DATETIME

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

**Ví dụ:**

```mysql
SELECT TRUNC_HOUR(’15-08-2019 10:01:30’)
-- 15-08-2019 10:00:00
```

### <span style="mso-list: Ignore;">4.1.20. </span>TRUNC\_DAY

Trả về giá trị thời gian với độ chính xác được tính theo ngày.

**Cú pháp:**

<span style="mso-spacerun: yes;"> </span>**TRUNC\_DAY** (truong\_du\_lieu\_thoi\_gian DATETIME)<span style="mso-spacerun: yes;"> </span>=&gt; DATETIME

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

**Ví dụ:**

```mysql
SELECT TRUNC_DAY (’15-08-2019 10:01:30’)
-- 15-08-2019 00:00:00
```

### <span style="mso-list: Ignore;">4.1.21. </span>TRUNC\_WEEK

Trả về giá trị thời gian với độ chính xác được tính theo tuần.

**Cú pháp:**

<span style="mso-spacerun: yes;"> </span>**TRUNC\_WEEK** (truong\_du\_lieu\_thoi\_gian DATETIME)<span style="mso-spacerun: yes;"> </span>=&gt; DATETIME

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

**Ví dụ:**

```mysql
SELECT TRUNC_WEEK(’15-08-2019 10:01:30’)
-- 04-08-2019 00:00:00
```

### <span style="mso-list: Ignore;">4.1.22. </span>TRUNC\_MONTH

Trả về giá trị thời gian với độ chính xác được tính theo tháng.

**Cú pháp:**

<span style="mso-spacerun: yes;"> </span>**TRUNC\_MONTH** (truong\_du\_lieu\_thoi\_gian DATETIME)<span style="mso-spacerun: yes;"> </span>=&gt; DATETIME

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

**Ví dụ:**

```mysql
SELECT TRUNC_MONTH(’15-08-2019 10:01:30’)
-- 01-08-2019 00:00:00
```

### <span style="mso-list: Ignore;">4.1.23. </span>TRUNC\_QUARTER

Trả về giá trị thời gian với độ chính xác được tính theo quý.

**Cú pháp:**

<span style="mso-spacerun: yes;"> </span>**TRUNC\_QUARTER** (truong\_du\_lieu\_thoi\_gian DATETIME)<span style="mso-spacerun: yes;"> </span>=&gt; <span style="mso-spacerun: yes;"> </span>DATETIME

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

**Ví dụ:**

```mysql
SELECT TRUNC_QUARTER(’15-08-2019 10:01:30’)
-- 01-07-2019 00:00:00
```

### <span style="mso-list: Ignore;">4.1.24. </span>TRUNC\_YEAR

Trả về giá trị thời gian với độ chính xác được tính theo năm.

**Cú pháp:**

<span style="mso-spacerun: yes;"> </span>**TRUNC\_YEAR** (truong\_du\_lieu\_thoi\_gian DATETIME)<span style="mso-spacerun: yes;"> </span>=&gt; DATETIME

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

**Ví dụ:**

```mysql
SELECT TRUNC_YEAR(’15-08-2019 10:01:30’)
-- 01-01-2019 00:00:00
```

### <span style="mso-list: Ignore;">4.1.25. </span>DOM

Trả về thứ tự ngày trong tháng từ một biểu thức thời gian.

**Cú pháp:**

<span style="mso-spacerun: yes;"> </span>**DOM** (truong\_du\_lieu\_thoi\_gian DATETIME) =&gt; INT

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

**Ví dụ:**

```mysql
SELECT DOM(’15-08-2019 10:01:30’)
-- 15
```

### <span style="mso-list: Ignore;">4.1.26. </span>DOW

Trả về thứ tự ngày trong tuần từ một biểu thức thời gian.

**Cú pháp:**

**DOW** (truong\_du\_lieu\_thoi\_gian DATETIME) =&gt; INT

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

```mysql
SELECT DOW(’15-08-2019 10:01:30’)
-- 4(15-08-2019 là thứ 5, 4 là thứ tự của thứ 5 trong tuần)
```

### <span style="mso-list: Ignore;">4.1.27. </span>DOY

Trả về thứ tự ngày trong năm từ một biểu thức thời gian.

**Cú pháp:**

**DOY** (truong\_du\_lieu\_thoi\_gian DATETIME) =&gt; INT

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

```mysql
SELECT DOY(’15-08-2019 10:01:30’)
-- 227(Năm 2019 có 365 ngày, 15-08-2019 là ngày thứ 227)
```

### <span style="mso-list: Ignore;">4.1.28. </span>WOY

Trả về thứ tự tuần trong năm từ một biểu thức thời gian.

**Cú pháp:**

**WOY** (truong\_du\_lieu\_thoi\_gian DATETIME) =&gt; INT

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

```mysql
SELECT WOY(’15-08-2019 10:01:30’)
-- 33(Một năm có 54 tuần, ngày 15-08-2019 là tuần thứ 33 trong năm)
```

### <span style="mso-list: Ignore;">4.1.29. </span>YWEEK

Trả về thứ tự tuần trong năm từ một biểu thức thời gian.

**Cú pháp:**

**YWEEK** (truong\_du\_lieu\_thoi\_gian DATETIME) =&gt; INT

<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

**Ví dụ:**

```mysql
SELECT YWEEK(’15-08-2019 10:01:30’)
-- 33
```

### <span style="mso-list: Ignore;">4.1.30. </span>EPOCH

Tính số giây đã trôi qua từ một mốc dữ liệu thời gian so với ngày 1 tháng 1 năm 1970 lúc 00:00:00 giờ UTC.

**Cú pháp:**

**EPOCH** (truong\_du\_lieu\_thoi\_gian DATETIME)<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\_thoi\_gian:** Biểu thức hoặc cột trả về kiểu dữ liệu thời gian/ngày tháng.

**Ví dụ:**

```mysql
SELECT EPOCH(’24/06/2024 10:01:30’)
-- 1719223290
```

```mysql
SELECT EPOCH(’01/01/1970 00:00:00’)
-- 0
```

<div class="eJOY__extension_root_class" id="bkmrk--2" style="all: unset;"></div><div class="eJOY__extension_root_class" id="bkmrk--3" style="all: unset;"></div>

# 4.2. Hàm toán học

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.1.<span style="font: 7.0pt 'Times New Roman';"> </span></span>ABS</span>

<span style="color: rgb(0, 0, 0);">Tính giá trị tuyệt đối của một biểu thức số.</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

<span style="color: rgb(0, 0, 0);">**ABS** (truong\_du\_lieu\_so Số)<span style="mso-spacerun: yes;"> </span>=&gt; Số</span>

<span style="color: rgb(0, 0, 0);"><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 dạng số cần tính giá trị tuyệt đối.</span>

**<span style="color: rgb(0, 0, 0);">Ví dụ về</span> <span style="color: rgb(0, 0, 0);">ABS</span>:**

```
SELECT ABS(-10)
-- 10
```

```mysql
SELECT ABS(0)
-- 0
```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.4.2.<span style="font: 7.0pt 'Times New Roman';"> </span></span>ACOS</span>

<span style="color: rgb(0, 0, 0);">Tính arccosine của một biểu thức số.</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

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

<span style="color: rgb(0, 0, 0);"><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:** Số có đơn vị là radians và kiểu dữ liệu dạng số.</span>

**<span style="color: rgb(0, 0, 0);">Ví dụ về</span> <span style="color: rgb(0, 0, 0);">ACOS</span>:**

```mysql
SELECT ACOS(0)
-- 1.5707963267948966
```

```mysql
SELECT ACOS(1.0)
-- 0
```

```mysql
SELECT ACOS(-1)
-- 3.141592653589793
```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.3.<span style="font: 7.0pt 'Times New Roman';"> </span></span>ADD</span>

<span style="color: rgb(0, 0, 0);">Tính giá trị của phép cộng giữa hai trường dữ liệu dạng số hoặc một trường dữ liệu và một số.</span>

<span style="color: rgb(0, 0, 0);">**Cú pháp:**</span>

<span style="color: rgb(0, 0, 0);">**ADD** (truong\_du\_lieu\_so\_1 Số, truong\_du\_lieu\_so\_2 Số) =&gt; Số</span>

<span style="color: rgb(0, 0, 0);">**<span style="font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-style: normal; font-variant: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman';"> </span></span></span>truong\_du\_lieu\_so\_1:** DOUBLE, INTEGER, BIGINT, DECIMAL, hoặc FLOAT.</span>

<span style="color: rgb(0, 0, 0);">**<span style="font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-style: normal; font-variant: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman';"> </span></span></span>truong\_du\_lieu\_so\_2:** DOUBLE, INTEGER, BIGINT, DECIMAL, hoặc FLOAT.</span>

<span style="color: rgb(0, 0, 0);">**Ví dụ về ADD với dữ liệu số :**</span>

```mysql
Select ADD(2, 3)
-- 6
```

<span style="color: rgb(0, 0, 0);">**Ví dụ về ADD cột "col" có hai giá trị \[2,3,4\]:**</span>

```mysql
Select ADD(col, 3)
-- 5
-- 6
-- 7
```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.4.<span style="font: 7.0pt 'Times New Roman';"> </span></span>ASIN</span>

<span style="color: rgb(0, 0, 0);">Tính arcsine của một biểu thức số.</span>

<span style="color: rgb(0, 0, 0);">**Cú pháp:**</span>

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

<span style="color: rgb(0, 0, 0);">**<span style="font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-style: normal; font-variant: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman';"> </span></span></span>truong\_du\_lieu\_so:** Số có đơn vị là radians và kiểu dữ liệu dạng số.</span>

<span style="color: rgb(0, 0, 0);">**Ví dụ về Asin:**</span>

```mysql
SELECT ASIN(0)
-- 0.0
```

```mysql
SELECT ASIN(1)
-- 1.5707963267948966
```

```mysql
SELECT ASIN(-1)
-- -1.5707963267948966
```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.5.<span style="font: 7.0pt 'Times New Roman';"> </span></span>ATAN</span>

<span style="color: rgb(0, 0, 0);">Tính arctang của một biểu thức số.</span>

<span style="color: rgb(0, 0, 0);">**Cú pháp:**</span>

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

<span style="color: rgb(0, 0, 0);">**<span style="font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-style: normal; font-variant: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman';"> </span></span></span>truong\_du\_lieu\_so:** Số có đơn vị là radians và kiểu dữ liệu dạng số.</span>

<span style="color: rgb(0, 0, 0);">**Ví dụ về ATAN:**</span>

```mysql
SELECT ATAN(-1)
-- -0.7853981633974483
```

```mysql
SELECT ATAN(19564.7)
-- 1.5707452143321894
```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.6.<span style="font: 7.0pt 'Times New Roman';"> </span></span>ATAN2</span>

<span style="color: rgb(0, 0, 0);">Tính arctang của tỷ số giữa hai trường dữ liệu.</span>

<span style="color: rgb(0, 0, 0);">**Cú pháp:**</span>

<span style="color: rgb(0, 0, 0);">**ATAN2** (y Số, x Số)<span style="mso-spacerun: yes;"> </span>=&gt; DOUBLE</span>

<span style="color: rgb(0, 0, 0);">**<span style="font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-style: normal; font-variant: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman';"> </span></span></span>y:** Giá trị đầu vào kiểu số thực đại diện cho tọa độ y, nằm trong khoảng từ âm vô cùng đến dương vô cùng.</span>

<span style="color: rgb(0, 0, 0);">**<span style="font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-style: normal; font-variant: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman';"> </span></span></span>x:** Giá trị đầu vào kiểu số thực đại diện cho tọa độ x, nằm trong khoảng từ âm vô cùng đến dương vô cùng.</span>

<span style="color: rgb(0, 0, 0);">**Ví dụ về ATAN2:**</span>

```mysql
SELECT ATAN2(1,0)
-- 1.5707452143321894
```

```mysql
SELECT ATAN2(0.0,1.0)
-- 0
```

```mysql
SELECT ATAN2(0.0,-1.0)
-- 3.141592653589793
```

```mysql
SELECT ATAN2(-0.00000000001,-1.0)
-- -3.141592653579793
```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.7.<span style="font: 7.0pt 'Times New Roman';"> </span></span>CBRT</span>

<span style="color: rgb(0, 0, 0);">Tính căn bậc 3 của các hàng trong một trường dữ liệu.</span>

<span style="color: rgb(0, 0, 0);">**Cú pháp:**</span>

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

<span style="color: rgb(0, 0, 0);">**<span style="font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-style: normal; font-variant: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman';"> </span></span></span>truong\_du\_lieu\_so:** trường dữ liệu dạng số cần tính căn bậc 3.</span>

<span style="color: rgb(0, 0, 0);">**Ví dụ về CBRT:**</span>

```mysql
SELECT CBRT(5)
-- 1.709975946676697

```

```mysql
SELECT CBRT(120)
-- 4.932424148653812

```

```mysql
SELECT CBRT(99.5)
-- 4.638049208321277

```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.8.<span style="font: 7.0pt 'Times New Roman';"> </span></span>CEIL</span>

<span style="color: rgb(0, 0, 0);">Trả về giá trị bằng hoặc lớn hơn gần nhất nếu là số thập phân của các hàng trong trường dữ liệu đầu vào.</span>

<span style="color: rgb(0, 0, 0);">**Cú pháp:**</span>

<span style="color: rgb(0, 0, 0);"><span style="mso-spacerun: yes;"> </span>**CEIL** (truong\_du\_lieu\_so Số)<span style="mso-spacerun: yes;"> </span>=&gt; INT</span>

<span style="color: rgb(0, 0, 0);">**Ví dụ về CEIL:**</span>

```mysql
SELECT CEIL(37.775420706711)
-- 38

```

```mysql
SELECT CEIL(3.1459)
-- 4

```

```mysql
SELECT CEIL(-37.775420706711)
-- -37

```

```mysql
SELECT CEIL(0)
-- 0

```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.9.<span style="font: 7.0pt 'Times New Roman';"> </span></span>COS</span>

<span style="color: rgb(0, 0, 0);">Tính cosine của một biểu thức số.</span>

<span style="color: rgb(0, 0, 0);">**Cú pháp:** </span>

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

<span style="color: rgb(0, 0, 0);"><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:** Số có đơn vị là radians và kiểu dữ liệu dạng số.</span>

<span style="color: rgb(0, 0, 0);"> **Ví dụ về COS:**</span>

```mysql
SELECT COS(0)
-- 1.0

```

```mysql
SELECT COS(1.0)
-- 0.5403023058681398

```

```mysql
SELECT COS(-1)
-- 0.5403023058681398

```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.10. </span>COSH</span>

<span style="color: rgb(0, 0, 0);">Tính hyperbolic cosine của một biểu thức số.</span>

<span style="color: rgb(0, 0, 0);">**Cú pháp:**</span>

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

<span style="color: rgb(0, 0, 0);"><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:** Số có đơn vị là radians và kiểu dữ liệu dạng số.</span>

<span style="color: rgb(0, 0, 0);">**Ví dụ về COSH:**</span>

```mysql
SELECT COSH(0)
-- 1.0

```

```mysql
SELECT COSH(1.0)
-- 1.543080634815244

```

```mysql
SELECT COSH(-1)
-- 1.543080634815244

```


### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.11. </span>COT</span>

<span style="color: rgb(0, 0, 0);">Tính cotang của một biểu thức số.</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

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

<span style="color: rgb(0, 0, 0);"><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:** Số có đơn vị là radians và kiểu dữ liệu dạng số.</span>

<span style="color: rgb(0, 0, 0);">**Ví dụ về COT:**</span>

```mysql
SELECT COT(0)
-- 1.0

```

```mysql
SELECT COT(1.0)
-- 0.6420926159343306

```

```mysql
SELECT COT(-1)
-- -0.6420926159343306

```


### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.12. </span>DEGRESS</span>

<span style="color: rgb(0, 0, 0);">Chuyển đổi đơn vị từ Radians sang Degress (Độ)</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

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

<span style="color: rgb(0, 0, 0);"><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:** Số có đơn vị là radians và có kiểu dữ liệu dạng số.</span>

**<span style="color: rgb(0, 0, 0);">Ví dụ về</span> <span style="color: rgb(0, 0, 0);">DEGRESS</span>:**

```mysql
SELECT DEGRESS(0)
-- 0.0

```

```mysql
SELECT DEGRESS(-1)
-- 57.29577951308232

```

### <span style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"><span style="background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;"><span style="mso-list: Ignore;">4.2.13. </span></span><span style="background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">DIV</span></span>

<span style="color: rgb(0, 0, 0);">Tính kết quả của phép chia giữa hai biểu thức đầu vào</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

<span style="color: rgb(0, 0, 0);">**<span style="mso-spacerun: yes;"> </span>DIV** (truong\_du\_lieu\_so\_1 Số, truong\_du\_lieu\_so\_2 Số)<span style="mso-spacerun: yes;"> </span>=&gt; Số</span>

<span style="color: rgb(0, 0, 0);"><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\_1:** Số bị chia</span>

<span style="color: rgb(0, 0, 0);"><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\_2:** Số chia, có thể là một số cụ thể hoặc một trường dữ liệu dạng số.</span>

**<span style="color: rgb(0, 0, 0);">Ví dụ về</span> <span style="color: rgb(0, 0, 0);">DIV</span>:**

```mysql
SELECT DIV(6,2)
-- 3
```

```mysql
SELECT DIV(revenue,order)
-- 3
-- 8
-- 9
```

### <span style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"><span style="background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;"><span style="mso-list: Ignore;">4.2.14. </span></span><span style="background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">DIVIDE</span></span>

<span style="color: rgb(0, 0, 0);">Tính kết quả của phép chia lấy số nguyên giữa hai biểu thức số</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

<span style="color: rgb(0, 0, 0);"><span style="mso-spacerun: yes;"> </span>**DIVIDE** (truong\_du\_lieu\_so\_1 Số, truong\_du\_lieu\_so\_2 Số)<span style="mso-spacerun: yes;"> </span>=&gt; Giá trị dạng số</span>

<span style="color: rgb(0, 0, 0);"><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\_1:** Số bị chia</span>

<span style="color: rgb(0, 0, 0);"><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\_2:** Số chia</span>

**<span style="color: rgb(0, 0, 0);">Ví dụ về</span> <span style="color: rgb(0, 0, 0);">DIVIDE</span>:**

```mysql
SELECT DIVIDE(revenue,2)
-- 1
-- 9
-- 20
```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.15. </span>EXP</span>

<span style="color: rgb(0, 0, 0);">Tính lũy thừa của số e (cơ số của logarit tự nhiên, xấp xỉ 2.718281...) với số mũ lần lượt là các giá trị trong một trường dữ liệu.</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

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

<span style="color: rgb(0, 0, 0);"><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:** Giá trị số mũ để nâng e lên</span>

**<span style="color: rgb(0, 0, 0);">Ví dụ về</span> <span style="color: rgb(0, 0, 0);">EXP</span>:**

```mysql
SELECT EXP(1)
-- 2.718281828459045
```

```mysql
SELECT EXP(10.0)
-- 22026.465794806718
```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.16. </span>FACTORIAL</span>

<span style="color: rgb(0, 0, 0);">Tính giai thừa của một giá trị số.</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

<span style="color: rgb(0, 0, 0);"><span style="mso-spacerun: yes;"> **FACTORIAL** </span>(gia\_tri INT)<span style="mso-spacerun: yes;"> </span>=&gt; BIGINT</span>

<span style="color: rgb(0, 0, 0);"><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>**gia\_tri:** Giá trị số nguyên từ 0- 20 trong một trường dữ liệu.</span>

**<span style="color: rgb(0, 0, 0);">Ví dụ về</span> <span style="color: rgb(0, 0, 0);"><span style="mso-spacerun: yes;">FACTORIAL</span></span>:**

```mysql
SELECT FACTORIAL(5)
-- 120
```

```mysql
SELECT FACTORIAL(20)
-- 2432902008176640000
```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.17. </span>FLOOR</span>

<span style="color: rgb(0, 0, 0);">Trả về giá trị bằng hoặc nhỏ hơn gần nhất nếu là số thập phân của trường dữ liệu đầu vào.</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

<span style="color: rgb(0, 0, 0);"><span style="mso-spacerun: yes;"> </span>**FLOOR** (truong\_du\_lieu\_so Số)<span style="mso-spacerun: yes;"> </span>=&gt; INT</span>

<span style="color: rgb(0, 0, 0);"><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:** Giá trị số lớn hơn 0</span>

**<span style="color: rgb(0, 0, 0);">Ví dụ về</span> <span style="color: rgb(0, 0, 0);">FLOOR</span>:**

```mysql
SELECT FLOOR(0)
-- 0
```

```mysql
SELECT CEIL(45.76)
-- 45
```

```mysql
SELECT FLOOR(-1.3)
-- -2
```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.18. </span>LOG</span>

<span style="color: rgb(0, 0, 0);">Tính logarit tự nhiên<span style="mso-tab-count: 1;"> </span> của các giá trị trong một trường dữ liệu.</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

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

<span style="color: rgb(0, 0, 0);"><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:** Giá trị số lớn hơn 0.</span>

**<span style="color: rgb(0, 0, 0);">Ví dụ về</span> <span style="color: rgb(0, 0, 0);">LOG</span>:**

```mysql
SELECT LOG(0)
-- null
```

```mysql
SELECT LOG(1)
-- 0
```

```mysql
SELECT LOG(5)
-- 1.6094379124341003
```

### <span style="mso-list: Ignore;">4.2.19. </span><span style="color: rgb(0, 0, 0); text-indent: 0in;">LOG10</span>

<span style="color: rgb(0, 0, 0);">Tính logarit cơ số 10 của trường dữ liệu đầu vào dạng số.</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

<span style="color: rgb(0, 0, 0);"><span style="mso-spacerun: yes;"> </span>**LOG10** (truong\_du\_lieu\_so Số)<span style="mso-spacerun: yes;"> </span>=&gt; Giá trị dạng số</span>

<span style="color: rgb(0, 0, 0);"><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:** Giá trị số lớn hơn 0.</span>

**<span style="color: rgb(0, 0, 0);">Ví dụ về</span> <span style="color: rgb(0, 0, 0);">LOG10</span>:**

```mysql
SELECT LOG10(20.5)
-- 1.3117538610557542
```

```mysql
SELECT LOG10(100)
-- 2.0
```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.20. </span>LOG1P</span>

<span style="color: rgb(0, 0, 0);">Tính logarit tự nhiên của 1 cộng một giá trị trong trường dữ liệu dạng số.</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

<span style="color: rgb(0, 0, 0);"><span style="mso-spacerun: yes;"> </span>**LOG1P** (truong\_du\_lieu\_so Số)<span style="mso-spacerun: yes;"> </span>=&gt; Giá trị dạng số</span>

<span style="color: rgb(0, 0, 0);"><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:** Giá trị số lớn hơn -1.</span>

<span style="color: rgb(0, 0, 0);">**Ví dụ về LOG1P**</span>

```mysql
SELECT LOG1P(0)
-- 0

```

```mysql
SELECT LOG1P(0.6931471805599453)
-- 0

```

```mysql
SELECT LOG1P(5)
-- 1.791759469228055

```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.21. </span>MULTIPLY</span>

<span style="color: rgb(0, 0, 0);">Tính kết quả của phép nhân giữa các dòng trong hai trường dữ liệu dạng số.</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

<span style="color: rgb(0, 0, 0);">**MULTIPLY** (truong\_du\_lieu\_so Số)<span style="mso-spacerun: yes;"> </span>=&gt; Giá trị dạng số</span>

<span style="color: rgb(0, 0, 0);"><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:** Giá trị của biểu thức muốn tính logarit.</span>

**<span style="color: rgb(0, 0, 0);">Ví dụ về</span> <span style="color: rgb(0, 0, 0);">MULTIPLY</span>:**

```mysql
SELECT MULTIPLY(10,2)
-- 20

```

```mysql
SELECT MULTIPLY(-2.0,2.0)
-- -4.0

```

```mysql
SELECT MULTIPLY(0,2)
-- 0

```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.22. </span>RADIANS</span>

<span style="color: rgb(0, 0, 0);">Chuyển đổi đơn vị từ Degress (Độ) sang Radians</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

<span style="color: rgb(0, 0, 0);">**RADIANS** (x Số)<span style="mso-spacerun: yes;"> </span>=&gt; DOUBLE</span>

<span style="color: rgb(0, 0, 0);"><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>**x:** Số có đơn vị là degress và kiểu dữ liệu là DOUBLE, INTEGER, BIGINT, DECIMAL, hoặc FLOAT.</span>

**<span style="color: rgb(0, 0, 0);">Ví dụ về</span> <span style="color: rgb(0, 0, 0);">RADIANS</span>:**

```mysql
SELECT RADIANS(45)
-- 0.7853981633974483

```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.23. </span>ROUND</span>

<span style="color: rgb(0, 0, 0);">Trả về giá trị sau khi làm tròn cho các giá trị đầu vào. Nếu không nhập số lượng chữ số thập phân số nguyên gần nhất sẽ được trả về.</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

<span style="color: rgb(0, 0, 0);">**ROUND** (truong\_du\_lieu\_so Số, Gia\_tri INT)<span style="mso-spacerun: yes;"> </span>=&gt; Số</span>

<span style="color: rgb(0, 0, 0);"><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:** Số cần làm tròn.</span>

<span style="color: rgb(0, 0, 0);"><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>**gia\_tri:** Số lượng chữ số ở phần thập phân.</span>

**<span style="color: rgb(0, 0, 0);">Ví dụ về</span> <span style="color: rgb(0, 0, 0);">ROUND</span>:**

```mysql
SELECT ROUND(24,0)
-- 24

```

```mysql
SELECT ROUND(24,-2)
-- 0

```

```mysql
SELECT ROUND(24.35,1)
-- 24.4

```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.24. </span>SIN</span>

<span style="color: rgb(0, 0, 0);">Tính sine của một biểu thức số.</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

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

<span style="color: rgb(0, 0, 0);"><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:** Số có đơn vị là radians và kiểu dữ liệu là DOUBLE, INTEGER, DECIMAL, hoặc FLOAT.</span>

**<span style="color: rgb(0, 0, 0);">Ví dụ về</span> <span style="color: rgb(0, 0, 0);">SIN</span>:**

```mysql
SELECT SIN(360)
-- 0.9589157234143065

```

```mysql
SELECT SIN(510.89)
-- 0.9282211721815067

```

```mysql
SELECT SIN(-1)
-- -0.8414709848078965

```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.25. </span>SINH</span>

<span style="color: rgb(0, 0, 0);">Tính hyperbolic sine của một biểu thức số.</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

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

<span style="color: rgb(0, 0, 0);"><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:** Số có đơn vị là radians và kiểu dữ liệu dạng số.</span>

<span style="line-height: 115%; color: rgb(0, 0, 0);"> <span style="color: rgb(0, 0, 0);">**Ví dụ về**</span> **<span style="color: rgb(0, 0, 0);">SINH</span>:**</span>

```mysql
SELECT SINH(1)
-- 1.1752011936438014

```

```mysql
SELECT SINH(1.5)
-- 2.1292794550948173

```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.26. </span>SQRT</span>

<span style="color: rgb(0, 0, 0);">Tính căn bậc hai của trường dữ liệu dạng số không âm.</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

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

<span style="color: rgb(0, 0, 0);"><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 căn bậc hai</span>

**<span style="color: rgb(0, 0, 0);">Ví dụ về</span> <span style="color: rgb(0, 0, 0);">SQRT</span>:**

```mysql
SELECT (25.25)
-- 5.024937810560445

```

```mysql
SELECT (25)
-- 5.0

```

#### <span style="line-height: 115%; color: rgb(0, 0, 0);"> </span>

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.26. </span>SUBTRACT</span>

<span style="color: rgb(0, 0, 0);">Tính kết quả của phép trừ giữa các dòng trong hai trường dữ liệu dạng số.</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

<span style="color: rgb(0, 0, 0);">**SUBTRACT** (truong\_du\_lieu\_so Số, so\_tru Số)<span style="mso-spacerun: yes;"> </span>=&gt; Giá trị dạng số</span>

<span style="color: rgb(0, 0, 0);"><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:** Giá trị của trường dữ liệu được coi như số bị trừ.</span>

<span style="color: rgb(0, 0, 0);"><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>**so\_tru:** Số trừ, có thể là một trường dữ liệu dạng số hoặc một số cụ thể</span>

**<span style="color: rgb(0, 0, 0);">Ví dụ về</span> <span style="color: rgb(0, 0, 0);">SUBTRACT</span>:**

```mysql
SELECT SUBTRACT (10,2)
-- 8

```

```mysql
SELECT SUBTRACT (-2.0,2.0)
-- -4.0

```

```mysql
SELECT SUBTRACT(0,2)
-- -2

```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.28. </span>TAN</span>

<span style="color: rgb(0, 0, 0);">Tính tang của một biểu thức số.</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

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

<span style="color: rgb(0, 0, 0);"><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:** Số có đơn vị là radians và kiểu dữ liệu là DOUBLE, INTEGER, DECIMAL, hoặc FLOAT</span>

**<span style="color: rgb(0, 0, 0);">Ví dụ về</span> <span style="color: rgb(0, 0, 0);">TAN</span>:**

```mysql
SELECT TAN(180.8)
-- -6.259341891872157

```

```mysql
SELECT TAN(1200)
-- -0.08862461268886584

```

### <span style="color: rgb(0, 0, 0);"><span style="mso-list: Ignore;">4.2.29. </span>TANH</span>

<span style="color: rgb(0, 0, 0);">Tính hyperbolic tang của một biểu thức số.</span>

**<span style="color: rgb(0, 0, 0);">Cú pháp:</span>**

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

<span style="color: rgb(0, 0, 0);"><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:** Số có đơn vị là radians và kiểu dữ liệu là: DOUBLE, INTEGER, BIGINT, DECIMAL, hoặc FLOAT.</span>

<span style="line-height: 115%; color: rgb(0, 0, 0);"> <span style="color: rgb(0, 0, 0);">**Ví dụ về**</span> **TANH:**</span>

```mysql
SELECT TANH(1.5)
-- 0.9051482536448664

```

```mysql
SELECT TANH(1)
-- 0.7615941559557649

```

# 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

# 4.4. Hàm chuyển đổi

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

<span style="color: rgb(0, 0, 0);">Chuyển đổi kiểu dữ liệu của một cột thành số nguyên BIGINT.</span>

<span style="color: rgb(0, 0, 0);">**Cú pháp:**</span>

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

<span style="color: rgb(0, 0, 0);"><span style="font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-style: normal; font-variant: normal; font-size-adjust: none; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman';"> </span></span></span>truong\_du\_lieu\_so: trường dữ liệu cần chuyển với kiểu dữ liệu là DOUBLE, INTEGER, BIGINT, DECIMAL, hoặc FLOAT.</span>

**<span style="color: rgb(0, 0, 0);">Ví dụ về CASTBIG</span>INT: cột col\[1,2,10.5\]:**

```mysql
SELECT CASTBIGINT(col)
-- 1, 2, 10

```

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

Chuyển đổi kiểu dữ liệu của một cột thành số thực DECIMAL.

**Cú pháp:**

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

<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 là DOUBLE, INTEGER, BIGINT, DECIMAL, hoặc FLOAT.

**<span style="mso-bidi-font-size: 13.0pt; line-height: 115%;"> Ví dụ về CASTDECIMAL: cột col\[1,2,10.5\]:</span>**

```mysql
SELECT CASTDECIMAL(col)
-- 1.0 ,2.0 , 10.5

```

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

Chuyển đổi kiểu dữ liệu của một cột thành nguyên Double.

**Cú pháp:**

**CASTDECIMAL** (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 đếm với kiểu dữ liệu là DOUBLE, INTEGER, BIGINT, DECIMAL, hoặc FLOAT.

**Ví dụ về CASTDECIMAL: cột col\[1,2,10.5\]:**

```mysql
SELECT CASTDECIMAL(col)
-- 1.0 ,2.0 , 10.5

```

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

Chuyển đổi kiểu dữ liệu của một cột thành số thực Float.

**Cú pháp:**

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

<span style="font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-style: normal; font-variant: normal; font-size-adjust: none; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: '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 là DOUBLE, INTEGER, BIGINT, DECIMAL, hoặc FLOAT.

**<span style="mso-bidi-font-size: 13.0pt; line-height: 115%;">Ví dụ về CASTDECIMAL: cột col\[1,2,10.5\]:</span>**

```mysql
SELECT CASTDECIMAL(col)
-- 1.0 ,2.0 , 10.5

```

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

<span style="mso-bookmark: _Hlk168548845;">Chuyển đổi kiểu dữ liệu của một cột thành số nguyên Int.</span>

**<span style="mso-bookmark: _Hlk168548845;">Cú pháp: </span>**

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

<span style="mso-bookmark: _Hlk168548845;"><span style="font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-style: normal; font-variant: normal; font-size-adjust: none; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: '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 là DOUBLE, INTEGER, BIGINT, DECIMAL, hoặc FLOAT.</span>

**Ví dụ về CASTDECIMAL: cột col\[1,2,10.5\]:**

```mysql
SELECT CASTDECIMAL(col)
-- 1 ,2 , 10

```

### <span style="mso-bookmark: _Hlk168548845;">4.4</span><span style="mso-list: Ignore;">.6.<span style="font: 7.0pt 'Times New Roman';"> </span></span>CASTLONG

Chuyển đổi kiểu dữ liệu của một cột thành số nguyên Long.

**Cú pháp:**

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

<span style="font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-style: normal; font-variant: normal; font-size-adjust: none; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: '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ố

**<span style="mso-bidi-font-size: 13.0pt; line-height: 115%;">Ví dụ về CASTDECIMAL: cột col\[1,2,10.5\]:</span>**

```mysql
SELECT CASTDECIMAL(col)
-- 1, 2, 10

```

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

Trả về giá trị băm cho trường dữ liệu được truyền vào, hàm HASH có giá trị null dù cho giá trị đầu vào null

**Cú pháp:**

**HASH** (truong\_du\_lieu) =&gt; BIGINT

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font-style: normal; font-variant: normal; font-size-adjust: none; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman';"> </span></span></span>truong\_du\_lieu: Giá trị được truyền vào để băm.

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

```mysql
SELECT HASH(’Ititan xin chào’)
-- -1965350004

```

```mysql
SELECT HASH(’15/08/2019 10:01:30’)
-- -44832748

```

# 4.5. Hàm chuỗi

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

Chuyển kí tự dạng chuỗi thành mã ASCII tương ứng.

**Cú pháp:**

**BTRIM** (truong\_du\_lieu STRING) =&gt; STRING

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**truong\_du\_lieu:** Chuỗi được truyền vào để loại bỏ khoảng trắng.

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

```mysql
SELECT ASCII(’iNet solutions’)

-- 105(mã ASCII của ký tự 'i')
```

```mysql
SELECT ASCII(’W’)

-- 87
```

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

Loại bỏ khoảng trắng ở đầu và cuối kí tự.

**Cú pháp:**

**BTRIM** (truong\_du\_lieu STRING) =&gt; STRING

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**truong\_du\_lieu:** Chuỗi được truyền vào để loại bỏ khoảng trắng.

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

```mysql
SELECT BTRIM(’    Ititan xin chào  ’)

-- Ititan xin chào
```

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

Nối hai hoặc nhiều chuỗi lại với nhau thành một chuỗi duy nhất.

**Cú pháp:**

**CONCAT** (truong\_du\_lieu\_1 STRING, truong\_du\_lieu\_2 STRING) =&gt; Chuỗi

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**truong\_du\_lieu\_1:** Chuỗi ban đầu.

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';">  </span></span></span>**truong\_du\_lieu\_2:** Trường dữ liệu dạng chuỗi hoặc chuỗi.

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

```mysql
SELECT CONCAT(’Ititan xin chào’,’iNet solutions’)

-- Ititan xin chàoiNet solutions
```

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

Chuyển đổi các chuỗi kí tự trong biểu thức với chữ cái đầu tiên của mỗi chữ được viết hoa.

**Cú pháp:**

**INITCAP** (truong\_du\_lieu STRING) =&gt; STRING

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**truong\_du\_lieu:** Chuỗi được truyền vào để xử lý.

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

```mysql
SELECT INITCAP(’ititan xin chào’)

-- Ititan Xin Chào
```

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

Kiểm tra sự tồn tại của một chuỗi con bên trong một chuỗi lớn hơn.

**Cú pháp:**

**INITCAP** (truong\_du\_lieu STRING, chuoi\_con STRING) =&gt; BOOL

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**truong\_du\_lieu:** Chuỗi được truyền vào để xử lý.

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**chuoi\_con:** Chuỗi được truyền vào để so sánh

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

```mysql
SELECT INSTR(’ititan xin chào’,’iti’)

-- 1
```

```mysql
SELECT INSTR(’ititan xin chào’,’abc’)

-- 0
```

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

Trả về độ dài của chuỗi kí tự.

**Cú pháp:**

**LENGTH** (truong\_du\_lieu STRING) =&gt; INT

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**truong\_du\_lieu:** Chuỗi được truyền vào để lấy độ dài.

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

```mysql
SELECT LENGTH(’Ititan xin chào’)

-- 15
```

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

Trả về tất cả các kí tự trong một chuỗi thành chữ không in hoa.

**Cú pháp:**

**LOWER** (truong\_du\_lieu STRING) =&gt; STRING

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**truong\_du\_lieu:** Chuỗi được truyền vào để viết hoa.

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

```mysql
SELECT LOWER(’ITITAN XIN CHÀO’)

-- ititan xin chào
```

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

Thêm kí tự được chỉ định hoặc khoảng trắng cho đến khi chuỗi đạt đủ số lượng.

**Cú pháp:**

**LPAD** (truong\_du\_lieu STRING, do\_dai INT, ki\_tu STRING) =&gt; Chuỗi

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';">  </span></span></span>**truong\_du\_lieu:** Chuỗi được truyền vào để thêm kí tự.

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';">  </span></span></span>**do\_dai:** Số lượng kí tự.

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';">  </span></span></span>**ki\_tu:** kí tự hoặc chuỗi để thêm.

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

```mysql
SELECT LPAD(’Ititan xin chào’, 20, ’ ’)

--      Ititan xin chào
```

```mysql
SELECT LPAD(’iNet Solution’, 18, ’i’)

-- iiiiiiNet Solution
```

<p class="callout info">**<span style="color: rgb(224, 62, 45);">Lưu ý</span><span style="color: rgb(224, 62, 45);">:</span>***<span style="color: rgb(224, 62, 45);"> </span>*Nếu ki\_tu không được nhập vào, giá trị mặc định là khoảng trắng sẽ được thêm. Nếu chuỗi lớn hơn do\_dai sẽ trả về chuỗi gốc ban đầu.</p>

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

Trả về giá trị lặp lại của các kí tự trong trường dữ liệu.

**Cú pháp:**

**LTRIM** (truong\_du\_lieu STRING) =&gt; STRING

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';">  </span></span></span>**truong\_du\_lieu:** Chuỗi được truyền vào để loại bỏ khoảng trắng.

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

```mysql
SELECT LTRIM(’iTitan xin chào’)

-- iTitan xin chào
```

### <span style="mso-list: Ignore;">4.5.10. </span>MASK\_FIRST

Giấu một số ký tự đầu tiên của trường dữ liệu dạng chuỗi.

**Cú pháp:**

**MASK\_FIRST** (truong\_du\_lieu STRING, do\_dai) =&gt; STRING

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**truong\_du\_lieu:** Chuỗi được truyền vào để loại bỏ khoảng trắng.

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**do\_dai:** số kí tự cần che giấu.

**Ví dụ về MASK\_FIRST:**

```mysql
SELECT MASK_FIRST(’Ititan xin chào’,4)

-- Xxxxan xin chào
```

### <span style="mso-list: Ignore;">4.5.11. </span>MASK\_LAST

Giấu một số ký tự đầu tiên của trường dữ liệu dạng chuỗi

**Cú pháp:**

**MASK\_LAST** (truong\_du\_lieu String, do\_dai) =&gt; String

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**truong\_du\_lieu:** Chuỗi được truyền vào để loại bỏ khoảng trắng.

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**do\_dai:** số kí tự cần che giấu.

**Ví dụ về MASK\_LAST:**

```mysql
SELECT MASK_LAST(’Ititan xin chào’,5)

-- Ititan xinxxxxx
```

### <span style="mso-list: Ignore;">4.5.12. </span>REPEAT

Trả về giá trị lặp lại của các kí tự trong trường dữ liệu.

**Cú pháp:**

**REVERSE** (truong\_du\_lieu STRING, so\_lan\_lap INT) =&gt; STRING

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**truong\_du\_lieu:** Chuỗi được truyền vào để lặp.

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**so\_lan\_lap:** Số lần lặp lại các kí tự

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

```mysql
SELECT REPEAT(’Ititan xin chào’)

-- Ititan xin chàoItitan xin chàoItitan xin chào
```

### <span style="mso-list: Ignore;">4.5.13. </span>REPLACE

Tìm kiếm và thay thế giá trị của một chuỗi kí tự.

**Cú pháp:**

**REPLACE** (truong\_du\_lieu STRING, ki\_tu\_1 STRING, ki\_tu\_2 STRING) =&gt; STRING

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**truong\_du\_lieu:** Chuỗi được truyền vào để thêm kí tự.

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';">  </span></span></span>**ki\_tu\_1:** Kí tự tìm kiếm.

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**ki\_tu\_2:** Kí tự thay thế.

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

```mysql
SELECT REPLACE(’Ititan xin chào’, ’i’, ’y’)

-- Itytan xyn chào
```

```mysql
SELECT REPLACE(’iNet Solution’, ’Solution’, ’xin chào’)

-- iNet xin chào
```

### <span style="mso-list: Ignore;">4.5.14. </span>REVERSE

Đảo ngược vị trí các kí tự của chuỗi trong biểu thức.

**Cú pháp:**

**REVERSE** (truong\_du\_lieu STRING) =&gt; STRING

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**truong\_du\_lieu:** Chuỗi được truyền vào để đảo ngược.

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

```mysql
SELECT REVERSE(’Ititan xin chào’)

-- oàhC nix natitI
```

### <span style="mso-list: Ignore;">4.5.15. </span>RTRIM

Loại bỏ các kí tự khoảng trắng ở cuối chuỗi kí tự.

**Cú pháp:**

**RTRIM** (truong\_du\_lieu STRING) =&gt; STRING

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**truong\_du\_lieu:** Chuỗi được truyền vào để loại bỏ khoảng trắng.

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

```mysql
SELECT RTRIM(’Ititan xin chào    ’)

-- Ititan xin chào
```

### <span style="mso-list: Ignore;">4.5.16. </span>STRPOS

Trả về vị trí lần đầu tiên xuất hiện của kí tự trong chuỗi.

**Cú pháp:**

**STRPOS** (truong\_du\_lieu STRING, ki\_tu STRING) =&gt; INT

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**truong\_du\_lieu:** Chuỗi được truyền vào để thêm kí tự.

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**ki\_tu:** Kí tự tìm kiếm.

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

```mysql
SELECT STRPOS(’Ititan xin chào’, ’i’)

-- 3
```

```mysql
SELECT STRPOS(’iNet Solution’, ’iNet’)

-- 1
```

```mysql
SELECT STRPOS(’iNet Solution’, ’x’)

-- 0
```

### <span style="mso-list: Ignore;">4.5.17.</span>STR\_LEFT

Trích xuất một phần chuỗi kí tự bên trái của cột được truyền vào.

**Cú pháp:**

**STR\_LEFT** (truong\_du\_lieu STRING, do\_dai INT) =&gt; STRING

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';">  </span></span></span>**truong\_du\_lieu:** Chuỗi được truyền vào để trích xuất.

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**do\_dai:** Số kí tự muốn trích xuất.

**Ví dụ về STR\_LEFT:**

```mysql
SELECT STR_LEFT(’Ititan xin chào’,3)

-- Iti
```

### <span style="mso-list: Ignore;">4.5.18. </span>STR\_RIGHT

Trích xuất một phần chuỗi kí tự bên phải của cột được truyền vào.

**Cú pháp:**

**RTRIM** (truong\_du\_lieu STRING, do\_dai INT) =&gt; STRING

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';">  </span></span></span>**truong\_du\_lieu:** Chuỗi được truyền vào để trích xuất.

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**do\_dai:** Số kí tự muốn trích xuất.

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

```mysql
SELECT RTRIM(’Ititan xin chào’,3)

-- hào
```

### <span style="mso-list: Ignore;">4.5.19. </span>SUBSTR

Trích xuất một phần chuỗi kí tự bên của trường dữ liệu được truyền vào.

**Cú pháp:**

**STR\_LEFT** (truong\_du\_lieu STRING, vi\_tri INT, do\_dai INT) =&gt; STRING

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**truong\_du\_lieu:** Chuỗi được truyền vào để trích xuất.

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**do\_dai:** Số kí tự muốn trích xuất.

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

```mysql
SELECT SUBSTR(’Ititan xin chào’,3,4)

-- itan
```

### <span style="mso-list: Ignore;">4.5.20.</span>UPPER

Trả về tất cả các kí tự trong một chuỗi thành chữ in hoa.

**Cú pháp:**

**UPPER** (truong\_du\_lieu STRING) =&gt; STRING

<span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>**truong\_du\_lieu:** Chuỗi được truyền vào để in hoa.

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

```mysql
SELECT UPPER(’Ititan xin chào’)

-- ITITAN XIN CHÀO
```