# Tài liệu sử dụng Cloud Query

# Chương 1. KIỂU DỮ LIỆU



# 1.1. Kiểu dữ liệu dạng số

**1.1. Kiểu dữ liệu dạng số**

**1.1.1. DECIMAL**  
DECIMAL là kiểu dữ liệu dạng số thập phân với miền giá trị và độ dài không cố định.

**Ví dụ:** 12.24, 976.54922

**1.1.2. INT**  
**INT** là kiểu dữ liệu số nguyên 4-bytes. Miền giá trị của **INT** mặc định từ -2,147,483,648 đến 2,147,483,647.

• **INT8:** Phạm vi từ -128 đến 127.  
• **INT16:** Phạm vi từ -32,768 đến 32,767.  
• **INT32:** Phạm vi từ -2,147,483,648 đến 2,147,483,647.  
• **INT64:** Phạm vi từ -9,223,372,036,854,775,808 đến 9,223,372,036,854,775,807.

**Ví dụ:** 5678

**1.1.3. SHORT**  
**SHORT** là kiểu dữ liệu số nguyên 2-bytes. Miền giá trị của **SHORT** mặc định từ -32,768 đến 32,767.

**Ví dụ:** 9382

**1.1.4. LONG**  
**LONG** là kiểu dữ liệu số nguyên 4-bytes. Miền giá trị của **LONG** mặc định từ -9,223,372,036,854,775,808 đến 9,223,372,036,854,775,807.

**Ví dụ:** 84700374

**1.1.5. UNIT**  
**UINT** là kiểu dữ liệu số nguyên không âm. Miền giá trị mặc định từ 0 đến 4,294,967,295. Ititan hỗ trợ **UNIT** dưới dạng ép kiểu dữ liệu.  
• **UINT16:** Phạm vi từ 0 đến 65,535.  
• **UINT32:** Phạm vi từ 0 đến 4,294,967,295.  
• **UINT64:** Phạm vi từ 0 đến 18,446,744,073,709,551,615.

**Ví dụ:** 1239, 8776, 26

**1.1.6. FLOAT**  
Được sử dụng để biểu diễn số thực (số có phần thập phân) với độ lớn 32 bit và độ chính xác tới 6 chữ số phần thập phân.

**Ví dụ:** 32.98

**1.1.7. DOUBLE**  
Được sử dụng để biểu diễn số thực (số có phần thập phân) với độ lớn 64 bit và độ chính xác tới 15 số thập phân.

**Ví dụ:** 652.583827523

# 1.2. Kiểu dữ liệu ngày tháng

**1.2. Kiểu dữ liệu ngày tháng**  
**1.2.1. DATE**  
Kiểu dữ liệu **DATE** cho phép tương tác và lưu trữ các dạng dữ liệu thời gian/ngày tháng.

**Ví dụ:** 30/05/2024 14:22:30

# 1.3. Kiểu dữ liệu nhị phân

**1.3. Kiểu dữ liệu nhị phân**  
**1.3.1. BOOLEAN**  
**BOOLEAN** là kiểu dữ liệu chỉ nhận 3 giá trị: True(1), False(0), Null

**Ví dụ:** True, False, True

# 1.4. Kiểu dữ liệu dạng chuỗi

**1.4. Kiểu dữ liệu dạng chuỗi**  
**1.4.1. STRING**  
**STRING** là kiểu dữ liệu dạng văn bản. Sql Lab hỗ trợ string theo định dạng Unicode.

**Ví dụ:** iTitan xin chào, iNet Solutions

**1.4.2. CHAR**  
**CHAR** là một kiểu dữ liệu cơ bản được sử dụng để lưu trữ các ký tự đơn lẻ, chẳng hạn như chữ cái, chữ số hoặc ký tự đặc biệt.

**Ví dụ:** a, b, @

# Chương 2. CÚ PHÁP TRUY VẤN



# 2.1. SELECT

Mệnh đề **SELECT** chỉ định danh sách các cột sẽ được trả về bởi truy vấn. Mặc dù nó xuất hiện đầu tiên trong câu lệnh, nhưng về mặt logic, các biểu thức trong mệnh đề này chỉ được thực thi ở giai đoạn cuối cùng. Mệnh đề **SELECT** có thể chứa các biểu thức biến đổi đầu ra, cũng như các hàm tổng hợp.

**<span style="mso-list: Ignore;">a)<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>Cú pháp:**

![](https://book.inetcloud.vn/uploads/images/gallery/2024-07/embedded-image-xzq0tsih.png)

**<span style="mso-list: Ignore;">b)<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>Ví dụ:**

Chọn tất cả các cột từ bảng "**table"**:

```mssql
SELECT *
FROM table
```

Thực thiện phép tính toán trên cột và thêm bí danh:

```mssql
SELECT add(col1,col2) as res, sqrt(col1) as root
FROM table
```

Trả về tổng số hàng trong bảng:

```mssql
SELECT count(*)
FROM table
```

**SELECT - \***

Chọn tất cả các cột từ bảng “**mat\_hang**”:

```mssql
SELECT *
FROM mat_hang
```

Biểu thức ngôi sao (\*) hoạt động như một ký tự đại diện (wildcard), chỉ định tất cả các cột từ một hoặc nhiều bảng trong truy vấn.

**SELECT - DISTINCT**

Chọn tất cả các mặt hàng duy nhất từ bảng "**mat\_hang".**

```mssql
SELECT DISTINCT *
FROM table
```

Mệnh đề **DISTINCT** có thể được sử dụng để chỉ trả về các hàng duy nhất trong kết quả – do đó, bất kỳ hàng trùng lặp nào cũng sẽ bị lọc ra.

<p class="callout info"><span class="" data-mention="Lưu ý:" id="bkmrk-l%C6%B0u-%C3%BD%3A" style="color: rgb(0, 0, 0);">**Lưu ý:** </span><span class="" data-mention="Các truy vấn bắt đầu bằng SELECT DISTINCT thực hiện việc loại bỏ các bản ghi trùng lặp, đây là một thao tác tốn kém tài nguyên. Do đó, chỉ sử dụng DISTINCT khi thực sự cần thiết." id="bkmrk-c%C3%A1c-truy-v%E1%BA%A5n-b%E1%BA%AFt-%C4%91%E1%BA%A7u">Các truy vấn bắt đầu bằng **SELECT DISTINCT** thực hiện việc loại bỏ các bản ghi trùng lặp, đây là một thao tác tốn kém tài nguyên. Do đó, chỉ sử dụng **DISTINCT** khi thực sự cần thiết.</span></p>

**SELECT – Hàm tổng hợp**

Trả về tổng số hàng trong bảng "**mat\_hang":**

```mssql
SELECT count(*)
FROM table
```

Trả về tổng số hàng trong bảng mat\_hang nhóm theo cột "**mat\_hang":**

```mssql
SELECT city, count(*)
FROM addresses
GROUP BY city;
```

# 2.2. FROM

Mệnh đề **FROM** chỉ định nguồn dữ liệu mà phần còn lại của truy vấn sẽ hoạt động trên đó. Về mặt logic, mệnh đề **FROM** là nơi bắt đầu thực hiện truy vấn. Mệnh đề **FROM** có thể chứa một bảng duy nhất, sự kết hợp của nhiều bảng được nối với nhau bằng mệnh đề **JOIN** hoặc một truy vấn **SELECT** khác bên trong truy vấn con.

**<span style="mso-list: Ignore;">a)<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>Cú pháp:**

![](https://book.inetcloud.vn/uploads/images/gallery/2024-07/embedded-image-la7a8qsb.png)

<span style="font-size: 12.0pt; line-height: 115%; mso-fareast-font-family: 'Times New Roman'; mso-no-proof: yes;"> </span>

**<span style="mso-list: Ignore;">b)<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>Ví dụ:**

Chọn tất cả các cột từ bảng “**table\_name**”:

```mssql
SELECT *
FROM table_name;
```

Chọn tất cả các cột từ bảng “**table\_name**” với bí danh tn:

```mssql
SELECT tn.*
FROM table_name tn;
```

Chọn tất cả các cột từ truy vấn con:

```mssql
SELECT *
FROM (SELECT * FROM table_name);
```

Chọn tất cả các cột từ hai bảng bằng phép "**Joins**":

```mssql
 SELECT *
FROM table_name
JOIN other_table ON (table_name.key = other_table.key);
```

# 2.3. JOINS

**JOINS** được sử dụng để nối hai bảng theo chiều ngang với mỗi hàng kết quả đều chứa thông tin từ cả hai bảng bên trái và bên phải.

**<span style="mso-list: Ignore;">a)<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>Outer Joins &amp; Inner Join**

**Outer Joins** &amp; **Inner Join** sử dụng các điều kiện để khớp các hàng từ hai bảng thông qua mệnh đề ON, thông thường là sử dụng các khóa, Tuy nhiên, cũng có nhiều trường hợp các hàng khớp với nhau thông qua các cột không phải khóa. Ititan cung cấp 4 loại **Outer Join** là: Left join, Right join và Full join

**<span style="mso-list: Ignore;">b)<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>Cross Join**

**Cross Join** là phép Joins không cần điều kiện, mỗi hàng từ bảng đầu tiên sẽ được kết hợp với tất cả các hàng từ bảng thứ hai. **Cross Join** thực hiện phép nhân Descartes (Cartesian product) giữa các bảng. Điều này có nghĩa là nó sẽ kết hợp từng hàng của bảng đầu tiên với từng hàng của bảng thứ hai.

**<span style="mso-list: Ignore;">c)<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>Minh họa:**

![](https://book.inetcloud.vn/uploads/images/gallery/2024-07/embedded-image-wi6lwazo.png)

# 2.4. WHERE

Mệnh đề **WHERE** chỉ định bất kỳ bộ lọc nào để áp dụng cho dữ liệu. Điều này cho phép người sử dụng lọc những thông tin cần thiết. Về mặt logic, mệnh đề **WHERE** được áp dụng ngay sau mệnh đề **FROM**.

**<span style="mso-list: Ignore;">a)<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>Cú pháp:**

<span style="font-size: 12.0pt; mso-fareast-font-family: 'Times New Roman'; mso-no-proof: yes;"> </span>

![](https://book.inetcloud.vn/uploads/images/gallery/2024-07/embedded-image-x6nxzfcu.png)

**<span style="mso-list: Ignore;">b)<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>Ví dụ:**

Chọn tất cả các hàng có id bằng 3:

```mysql
SELECT *
FROM table_name
WHERE id = 3;

```

Chọn tất cả các hàng khớp với biểu thức "**Like**":

```mysql
SELECT *
FROM table_name
WHERE name LIKE '%mark%';

```

Chọn tất cả các hàng có id bằng 3 hoặc bằng 7:

```mysql
SELECT *
FROM table_name
WHERE id = 3 OR id = 7;

```

# 2.5. GROUP BY

Mệnh đề **GROUP BY** chỉ định những cột nhóm sẽ được sử dụng để thực hiện các phép tổng hợp nào trong mệnh đề **SELECT**. Nếu mệnh đề **GROUP BY** được chỉ định, truy vấn luôn là truy vấn tổng hợp, ngay cả khi không có phép tổng hợp nào có trong mệnh đề **SELECT**.

Khi mệnh đề **GROUP BY** được chỉ định, tất cả các bộ dữ liệu có dữ liệu khớp trong các cột nhóm (tức là tất cả các bộ dữ liệu thuộc cùng một nhóm) sẽ được kết hợp. Các giá trị của chính các cột nhóm không thay đổi và bất kỳ cột nào khác có thể được kết hợp bằng cách sử dụng hàm tổng hợp.

**<span style="mso-list: Ignore;">a)<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>Cú pháp:**

![](https://book.inetcloud.vn/uploads/images/gallery/2024-07/embedded-image-cavemnr0.png)

<span style="font-size: 12.0pt; mso-fareast-font-family: 'Times New Roman'; mso-no-proof: yes;"> </span>

**<span style="mso-list: Ignore;">b)<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>Ví dụ:**

Đếm số lượng địa chỉ có trong các thành phố khác nhau:

```mysql
SELECT city, count(*)
FROM addresses
GROUP BY city;
```

Tính trung bình thu nhập theo từng khu vực đường trong các thành phố khác nhau:

```mysql
SELECT city, street_name, avg(income)
FROM addresses
GROUP BY city, street_name;
```

# 2.6. ORDER BY

**ORDER BY** sắp xếp kết quả đầu ra của truy vấn. Về mặt logic, nó được áp dụng ở cuối truy vấn. Mệnh đề **ORDER BY** sắp xếp các hàng theo tiêu chí sắp xếp theo thứ tự tăng dần hoặc giảm dần. Mệnh đề **ORDER BY** có thể chứa một hoặc nhiều biểu thức. Mỗi biểu thức có thể tùy ý được theo sau bởi một công cụ sửa đổi thứ tự (ASC hoặc DESC, mặc định là ASC)

**<span style="mso-list: Ignore;">a)<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>Cú pháp:**

![](https://book.inetcloud.vn/uploads/images/gallery/2024-07/embedded-image-r8aowmp6.png)

<span style="font-size: 12.0pt; mso-fareast-font-family: 'Times New Roman'; mso-no-proof: yes;"> </span>

**<span style="mso-list: Ignore;">b)<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>Ví dụ:**

Sắp xếp thứ tự các hàng dữ liệu theo cột "**city**":

```mysql
SELECT *
FROM table_name
ORDER BY name;

```

Sắp xếp thứ tự các hàng dữ liệu theo cột "**city**" theo thứ tự giảm giần:

```mysql
SELECT *
FROM table_name
ORDER BY city DESC;

```

# 2.7. LIMIT

**LIMIT** là một mệnh đề dùng để giới hạn số lượng hàng dữ liệu được trả về trong một truy vấn . Về mặt logic, nó được áp dụng ở cuối truy vấn. Mệnh đề **LIMIT** hạn chế số lượng hàng được truy vấn.

**<span style="mso-list: Ignore;">a)<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>Cú pháp:**

**<span style="mso-no-proof: yes;"> </span>**

![](https://book.inetcloud.vn/uploads/images/gallery/2024-07/embedded-image-7ayb1opb.png)

**<span style="mso-list: Ignore;">b)<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>Ví dụ:**

Lấy 5 hàng dữ liệu trong truy vấn.

```mysql
SELECT *
FROM table
LIMIT 5;

```

Lấy 5 giá trị lớn nhất trong cột “**name**”.

```mysql
SELECT city, count(*) AS population
FROM table
GROUP BY name
ORDER BY value DESC
LIMIT 5;

```

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

# Chương 3. BIỂU THỨC



# 3.1. CASE

**CASE** thực hiện việc thêm giá trị cho một cột mới dựa trên điều kiện.

**<span style="mso-no-proof: yes;"><span style="mso-list: Ignore;">a)<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>Cú pháp:**

![](https://book.inetcloud.vn/uploads/images/gallery/2024-07/embedded-image-eeuimvna.png)

<span style="font-size: 12.0pt; mso-fareast-font-family: 'Times New Roman'; mso-no-proof: yes;"> </span>

**<span style="mso-list: Ignore;">b)<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>Ví dụ:**

Thêm giá trị theo điều kiện của cột i:

```mysql
-- i[1,2,3]
SELECT i, CASE WHEN i > 2 THEN 1 ELSE 0 END AS test
FROM integers;

```

<table border="1" cellpadding="0" cellspacing="0" id="bkmrk-i-test-1-0-2-0-3-1-1" style="border-collapse: collapse; width: 96pt; border-spacing: 1px; border: 0px groove rgb(0, 0, 0);" width="128"><colgroup><col span="2" style="width: 48pt;" width="64"></col></colgroup><thead><tr style="height: 15.0pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;"><td class="xl63" height="20" style="height: 15pt; width: 48pt; padding: 1px; border-color: rgb(0, 0, 0); background-color: rgb(217, 217, 217);" width="64">**<span style="mso-color-alt: windowtext;">i</span>**</td><td class="xl64" style="width: 48pt; padding: 1px; border-color: rgb(0, 0, 0); background-color: rgb(217, 217, 217);" width="64">**<span style="mso-color-alt: windowtext;">test</span>**</td></tr></thead><tbody><tr style="height: 15.0pt; mso-yfti-irow: 1;"><td class="xl65 align-left" height="20" style="height: 15pt; width: 48pt; padding: 1px; border-color: rgb(0, 0, 0);" width="64">1</td><td class="xl66 align-left" style="width: 48pt; padding: 1px; border-color: rgb(0, 0, 0);" width="64">0</td></tr><tr style="height: 15.0pt; mso-yfti-irow: 2;"><td class="xl65 align-left" height="20" style="height: 15pt; width: 48pt; padding: 1px; border-color: rgb(0, 0, 0);" width="64">2</td><td class="xl66 align-left" style="width: 48pt; padding: 1px; border-color: rgb(0, 0, 0);" width="64">0</td></tr><tr style="height: 15.0pt; mso-yfti-irow: 3; mso-yfti-lastrow: yes;"><td class="xl65 align-left" height="20" style="height: 15pt; width: 48pt; padding: 1px; border-color: rgb(0, 0, 0);" width="64">3</td><td class="xl66 align-left" style="width: 48pt; padding: 1px; border-color: rgb(0, 0, 0);" width="64">1</td></tr></tbody></table>

Phần **WHEN<span style="mso-spacerun: yes;"> </span>THEN** của biểu thức điều kiện **CASE** có thể được nối tiếp, bất cứ khi nào bất kỳ điều kiện nào trả về giá trị true cho một bộ đơn lẻ, biểu thức tương ứng sẽ được đánh giá và trả về.

```mysql
SELECT i, CASE WHEN i = 1 THEN 10 WHEN i = 2 THEN 20 ELSE 0 END AS test
FROM integers;

```

<table border="1" cellpadding="0" cellspacing="0" id="bkmrk-i-test-1-10-2-20-3-0" style="border-collapse: collapse; width: 96px; border-spacing: 1px; border: 0px groove rgb(0, 0, 0);" width="128"><colgroup><col span="2" style="width: 48pt;" width="64"></col></colgroup><thead><tr style="height: 15.0pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;"><td class="xl63" height="20" style="height: 15pt; width: 48pt; padding: 1px; border-color: rgb(0, 0, 0); background-color: rgb(217, 217, 217);" width="64"><span style="mso-color-alt: windowtext;">i</span></td><td class="xl64" style="width: 48pt; padding: 1px; border-color: rgb(0, 0, 0); background-color: rgb(217, 217, 217);" width="64"><span style="mso-color-alt: windowtext;">test</span></td></tr></thead><tbody><tr style="height: 15.0pt; mso-yfti-irow: 1;"><td class="xl65 align-left" height="20" style="height: 15pt; width: 48pt; padding: 1px; border-color: rgb(0, 0, 0);" width="64">1</td><td class="xl66 align-left" style="width: 48pt; padding: 1px; border-color: rgb(0, 0, 0);" width="64">10</td></tr><tr style="height: 15.0pt; mso-yfti-irow: 2;"><td class="xl65 align-left" height="20" style="height: 15pt; width: 48pt; padding: 1px; border-color: rgb(0, 0, 0);" width="64">2</td><td class="xl66 align-left" style="width: 48pt; padding: 1px; border-color: rgb(0, 0, 0);" width="64">20</td></tr><tr style="height: 15.0pt; mso-yfti-irow: 3; mso-yfti-lastrow: yes;"><td class="xl65 align-left" height="20" style="height: 15pt; width: 48pt; padding: 1px; border-color: rgb(0, 0, 0);" width="64">3</td><td class="xl66 align-left" style="width: 48pt; padding: 1px; border-color: rgb(0, 0, 0);" width="64">0</td></tr></tbody></table>

# 3.2. So sánh

**Toán tử so sánh:**

SQL\_Lab cung cấp 6 toán tử so sánh tiêu chuẩn. Bất cứ khi nào một trong hai đối số đầu vào là **NULL** thì đầu ra của phép so sánh là **NULL**.

**<span style="mso-bidi-font-size: 13.0pt; line-height: 115%;">Cú pháp:</span>**

![](https://book.inetcloud.vn/uploads/images/gallery/2024-07/embedded-image-jmcrvhrj.png)

<span style="font-size: 12.0pt; mso-fareast-font-family: 'Times New Roman'; mso-no-proof: yes;"> </span>

**<span style="mso-bidi-font-size: 13.0pt; mso-fareast-font-family: 'Times New Roman';">Toán tử so sánh:</span>**

<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" id="bkmrk-to%C3%A1n-t%E1%BB%AD-m%C3%B4-t%E1%BA%A3-v%C3%AD-d%E1%BB%A5-" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt;"><thead><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; height: 22.7pt;"><td style="width: 90.7pt; border: solid black 1.0pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="121">**Toán tử**

</td><td style="width: 148.6pt; border: solid black 1.0pt; border-left: none; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="198">**Mô tả**

</td><td style="width: 85.05pt; border: solid black 1.0pt; border-left: none; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="113">**Ví dụ**

</td><td style="width: 85.05pt; border: solid black 1.0pt; border-left: none; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="113">**Kết quả**

</td></tr></thead><tbody><tr style="mso-yfti-irow: 1; height: 22.7pt;"><td style="width: 90.7pt; border: solid black 1.0pt; border-top: none; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="121">&lt;

</td><td style="width: 148.6pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="198">Bé hơn

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="113">2 &lt; 3

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="113">True

</td></tr><tr style="mso-yfti-irow: 2; height: 22.7pt;"><td style="width: 90.7pt; border: solid black 1.0pt; border-top: none; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="121">&gt;

</td><td style="width: 148.6pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="198">Lớn hơn

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="113">2 &gt; 3

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="113">False

</td></tr><tr style="mso-yfti-irow: 3; height: 22.7pt;"><td style="width: 90.7pt; border: solid black 1.0pt; border-top: none; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="121">&lt;=

</td><td style="width: 148.6pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="198">Bé hơn hoặc bằng

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="113">2 &lt;= 3

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="113">True

</td></tr><tr style="mso-yfti-irow: 4; height: 22.7pt;"><td style="width: 90.7pt; border: solid black 1.0pt; border-top: none; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="121">&gt;=

</td><td style="width: 148.6pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="198">Lớn hơn hoặc bằng

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="113">4 &gt;= Null

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="113">Null

</td></tr><tr style="mso-yfti-irow: 5; height: 22.7pt;"><td style="width: 90.7pt; border: solid black 1.0pt; border-top: none; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="121">=

</td><td style="width: 148.6pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="198">Bằng

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="113">Null = Null

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="113">Null

</td></tr><tr style="mso-yfti-irow: 6; mso-yfti-lastrow: yes; height: 22.7pt;"><td style="width: 90.7pt; border: solid black 1.0pt; border-top: none; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="121">&lt; &gt; hoặc

</td><td style="width: 148.6pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="198">Không bằng

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="113">2 &lt; &gt; 2

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 22.7pt;" valign="top" width="113">False

</td></tr></tbody></table>

**BEETWEEN và IS<span style="mso-spacerun: yes;"> </span>\[NOT\] NULL**

Bên cạnh các toán tử so sánh chuẩn, còn có các toán tử **BETWEEN** và **IS (NOT) NULL**. Các toán tử này hoạt động rất giống các toán tử, nhưng có cú pháp đặc biệt theo chuẩn SQL. Chúng được hiển thị trong bảng bên dưới.

**Cú pháp:**

<span style="mso-no-proof: yes;"> </span>

 ![](https://book.inetcloud.vn/uploads/images/gallery/2024-07/embedded-image-2c0ovliy.png)

**BEETWEEN và IS<span style="mso-spacerun: yes;"> </span>\[NOT\] NULL**

<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" id="bkmrk-thu%E1%BB%99c-t%C3%ADnh-m%C3%B4-t%E1%BA%A3-a-b" style="border-collapse: collapse; border: none; width: 62.0238%; height: 159.587px;"><thead><tr style="height: 30.2625px;"><td style="width: 37.4732%; border: 1pt solid black; padding: 0in 5.4pt; height: 30.2625px;" valign="top" width="243">**Thuộc tính**

</td><td style="width: 62.6806%; border-top: 1pt solid black; border-right: 1pt solid black; border-bottom: 1pt solid black; border-image: initial; border-left: none; padding: 0in 5.4pt; height: 30.2625px;" valign="top" width="331">**Mô tả**

</td></tr></thead><tbody><tr style="height: 30.2625px;"><td style="width: 37.4732%; border-right: 1pt solid black; border-bottom: 1pt solid black; border-left: 1pt solid black; border-image: initial; border-top: none; padding: 0in 5.4pt; height: 30.2625px;" valign="top" width="243">a BETWEEN x AND y

</td><td style="width: 62.6806%; border-top: none; border-left: none; border-bottom: 1pt solid black; border-right: 1pt solid black; padding: 0in 5.4pt; height: 30.2625px;" valign="top" width="331">x &lt; a và a &lt; y

</td></tr><tr style="height: 30.2625px;"><td style="width: 37.4732%; border-right: 1pt solid black; border-bottom: 1pt solid black; border-left: 1pt solid black; border-image: initial; border-top: none; padding: 0in 5.4pt; height: 30.2625px;" valign="top" width="243">a NOT BETWEEN x AND y

</td><td style="width: 62.6806%; border-top: none; border-left: none; border-bottom: 1pt solid black; border-right: 1pt solid black; padding: 0in 5.4pt; height: 30.2625px;" valign="top" width="331">x &gt; a và a &gt; y

</td></tr><tr style="height: 34.4px;"><td style="width: 37.4732%; border-right: 1pt solid black; border-bottom: 1pt solid black; border-left: 1pt solid black; border-image: initial; border-top: none; padding: 0in 5.4pt; height: 34.4px;" valign="top" width="243">IS NULL

</td><td style="width: 62.6806%; border-top: none; border-left: none; border-bottom: 1pt solid black; border-right: 1pt solid black; padding: 0in 5.4pt; height: 34.4px;" valign="top" width="331">true nếu biểu thức NULL, false nếu ngược lại

</td></tr><tr style="height: 34.4px;"><td style="width: 37.4732%; border-right: 1pt solid black; border-bottom: 1pt solid black; border-left: 1pt solid black; border-image: initial; border-top: none; padding: 0in 5.4pt; height: 34.4px;" valign="top" width="243">IS NOT NULL<span style="mso-tab-count: 1;"> </span>

</td><td style="width: 62.6806%; border-top: none; border-left: none; border-bottom: 1pt solid black; border-right: 1pt solid black; padding: 0in 5.4pt; height: 34.4px;" valign="top" width="331">false nếu biểu thức NULL, true nếu ngược lại

</td></tr></tbody></table>

<p class="callout info">**<span style="color: rgb(0, 0, 0);">Lưu ý: </span>BETWEEN** và **NOT BETWEEN** chỉ tương đương với các ví dụ bên dưới trong trường hợp cả a, x và y đều cùng kiểu, vì **BETWEEN** sẽ ép kiểu tất cả các đầu vào của nó thành cùng kiểu.</p>

# 3.3. Toán tử IN

**<span style="mso-list: Ignore;">a)<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>Cú pháp**

![](https://book.inetcloud.vn/uploads/images/gallery/2024-07/embedded-image-1gtwykqw.png)

**<span style="font-size: 12.0pt; mso-fareast-font-family: 'Times New Roman'; mso-no-proof: yes;"> </span>**

**<span style="mso-list: Ignore;">b)<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>Toán tử**

**IN**

Toán tử **IN** kiểm tra sự chứa đựng của biểu thức bên trái bên trong tập hợp các biểu thức ở phía bên phải (P). Toán tử **IN** trả về true nếu biểu thức có trong P, false nếu biểu thức không có trong P và P không có giá trị NULL hoặc NULL nếu biểu thức không có trong P và P có giá trị NULL.

```mysql
SELECT 'Toán' IN ('Toán', 'Văn');
-- true

```

```mysql
SELECT 'Toán' IN ('Văn', 'Anh');
-- false

```

```mysql
SELECT 'Toán' IN ('Văn', Toán', NULL);
-- true

```

```mysql
SELECT 'Toán' IN ('Văn', 'Anh', NULL);
-- NULL

```

**NOT IN**

**NOT IN** có thể được sử dụng để kiểm tra xem một phần tử có tồn tại trong tập hợp hay không. x **NOT IN** y tương đương với **NOT**(x **IN** y)

##   

# 3.4. Toán tử logic

**<span style="mso-list: Ignore;">a)<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>Cú pháp:**

![](https://book.inetcloud.vn/uploads/images/gallery/2024-07/embedded-image-6f5rq4g0.png)

<span style="font-size: 12.0pt; mso-fareast-font-family: 'Times New Roman'; mso-no-proof: yes;"> </span>

**<span style="mso-bidi-font-size: 13.0pt; mso-fareast-font-family: 'Times New Roman';"> </span><span style="mso-bidi-font-size: 13.0pt; mso-fareast-font-family: 'Times New Roman';">b) </span><span style="mso-bidi-font-size: 13.0pt; mso-fareast-font-family: 'Times New Roman';">Toán từ:</span>**

**Toán tử nhị phân:**

<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" id="bkmrk-a-b-a-and-b-a-or-b-t" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt;"><thead><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; height: 17.0pt;"><td style="width: 90.7pt; border: 1pt solid black; background: rgb(217, 217, 217); padding: 0in 5.4pt; height: 17pt;" valign="top" width="121"><span style="color: black; mso-color-alt: windowtext;">a</span>

</td><td style="width: 91.9pt; border-top: 1pt solid black; border-right: 1pt solid black; border-bottom: 1pt solid black; border-image: initial; border-left: none; background: rgb(217, 217, 217); padding: 0in 5.4pt; height: 17pt;" valign="top" width="123"><span style="color: black; mso-color-alt: windowtext;">b</span>

</td><td style="width: 85.05pt; border-top: 1pt solid black; border-right: 1pt solid black; border-bottom: 1pt solid black; border-image: initial; border-left: none; background: rgb(217, 217, 217); padding: 0in 5.4pt; height: 17pt;" valign="top" width="113"><span style="color: black; mso-color-alt: windowtext;">a AND b</span>

</td><td style="width: 85.05pt; border-top: 1pt solid black; border-right: 1pt solid black; border-bottom: 1pt solid black; border-image: initial; border-left: none; background: rgb(217, 217, 217); padding: 0in 5.4pt; height: 17pt;" valign="top" width="113"><span style="color: black; mso-color-alt: windowtext;">a OR b</span>

</td></tr></thead><tbody><tr style="mso-yfti-irow: 1; height: 17.0pt;"><td style="width: 90.7pt; border: solid black 1.0pt; border-top: none; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="121">true

</td><td style="width: 91.9pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="123">true

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="113">true

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="113">True

</td></tr><tr style="mso-yfti-irow: 2; height: 17.0pt;"><td style="width: 90.7pt; border: solid black 1.0pt; border-top: none; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="121">true

</td><td style="width: 91.9pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="123">false

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="113">false

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="113">false

</td></tr><tr style="mso-yfti-irow: 3; height: 17.0pt;"><td style="width: 90.7pt; border: solid black 1.0pt; border-top: none; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="121">true

</td><td style="width: 91.9pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="123">NULL

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="113">NULL

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="113">true

</td></tr><tr style="mso-yfti-irow: 4; height: 17.0pt;"><td style="width: 90.7pt; border: solid black 1.0pt; border-top: none; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="121">false

</td><td style="width: 91.9pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="123">false

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="113">false

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="113">false

</td></tr><tr style="mso-yfti-irow: 5; height: 17.0pt;"><td style="width: 90.7pt; border: solid black 1.0pt; border-top: none; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="121">false

</td><td style="width: 91.9pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="123">NULL

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="113">false

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="113">NULL

</td></tr><tr style="mso-yfti-irow: 6; mso-yfti-lastrow: yes; height: 17.0pt;"><td style="width: 90.7pt; border: solid black 1.0pt; border-top: none; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="121">NULL

</td><td style="width: 91.9pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="123">NULL

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="113">NULL

</td><td style="width: 85.05pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="113">NULL

</td></tr></tbody></table>

<p class="callout info"><span style="color: black; mso-color-alt: windowtext;"><span style="color: rgb(0, 0, 0);">**Lưu ý:** </span>Các toán tử logic liên quan đến NULL không phải lúc nào cũng có giá trị là NULL.   
Ví dụ: NULL AND false sẽ đánh giá là sai và NULL OR true sẽ đánh giá là đúng. Dưới đây là các bảng sự thật đầy đủ.</span></p>

**Toán tử một ngôi:**

<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" id="bkmrk-a-not-a-true-false-f" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt;"><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; height: 17.0pt;"><td style="width: 90.7pt; border: solid black 1.0pt; mso-border-alt: solid black .5pt; background: #D9D9D9; mso-background-themecolor: background1; mso-background-themeshade: 217; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="121"><span style="color: black; mso-color-alt: windowtext;">a</span>

</td><td style="width: 91.9pt; border: solid black 1.0pt; border-left: none; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; background: #D9D9D9; mso-background-themecolor: background1; mso-background-themeshade: 217; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="123"><span style="color: black; mso-color-alt: windowtext;">NOT a</span>

</td></tr><tr style="mso-yfti-irow: 1; height: 17.0pt;"><td style="width: 90.7pt; border: solid black 1.0pt; border-top: none; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="121">true

</td><td style="width: 91.9pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="123">false

</td></tr><tr style="mso-yfti-irow: 2; height: 17.0pt;"><td style="width: 90.7pt; border: solid black 1.0pt; border-top: none; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="121">false

</td><td style="width: 91.9pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="123">true

</td></tr><tr style="mso-yfti-irow: 3; mso-yfti-lastrow: yes; height: 17.0pt;"><td style="width: 90.7pt; border: solid black 1.0pt; border-top: none; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="121">NULL

</td><td style="width: 91.9pt; border-top: none; border-left: none; border-bottom: solid black 1.0pt; border-right: solid black 1.0pt; mso-border-top-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; padding: 0in 5.4pt 0in 5.4pt; height: 17.0pt;" valign="top" width="123">NULL

</td></tr></tbody></table>

# 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
```