Preface

@ TOC
This article will discuss the various operators used in SQL in the following order:

This article will discuss the various operators used in SQL in the following order:

  • What is an operator?
  • Classification of operators:

Arithmetic Operator
Comparison operator
Logical Operators

What is an operator?

SQL operators are reserved keywords used to perform arithmetic, logic, and comparison operations in the WHERE clause of SQL statements. Operators act as connectives in SQL statements to satisfy multiple conditions in the statement.

在这里插入图片描述

Classification of operators:

Arithmetic Operator

These operators are used to perform operations such as addition, multiplication, and subtraction.

在这里插入图片描述

在这里插入图片描述

example:

SELECT 40 + 20;
 
SELECT 40 - 20;
 
SELECT 40 * 20;
 
SELECT 40 / 20;
 
SELECT 40 % 20;

Output:

60
 
20
 
800
 
2
 
0

Comparison operator

These operators are used to perform operations such as equals, greater than, and less than.

在这里插入图片描述

在这里插入图片描述

example:

For a better understanding, I will consider the following table to perform various operations.
在这里插入图片描述

Example (equal to):

SELECT * FROM Students
WHERE Age = 20;

Output:

在这里插入图片描述

Example (greater than):

SELECT * FROM students
WHERE Age > 23;

Output:

在这里插入图片描述

Example (less than or equal to):

SELECT * FROM students
WHERE Age <= 21;

Output:

在这里插入图片描述

Example (not equal to):

SELECT * FROM students
WHERE Age <> 25;

Output:

在这里插入图片描述

Logical Operators

在这里插入图片描述

example:

I will consider the student table mentioned above to perform some operations.

Example (ANY)

SELECT * FROM Students
WHERE Age > ANY (SELECT Age FROM Students WHERE Age > 21);

Output: 在这里插入图片描述
Example (BETWEEN & AND)

SELECT * FROM Students
WHERE Age BETWEEN 22 AND 25;

Output:

在这里插入图片描述
Example (IN)

SELECT * FROM Students
WHERE Age IN('23', '20');

Output:

在这里插入图片描述

In this article, I just cite the most common example. Of course, database and network technology are not the same. The network has many principles, but the database is biased towards actual combat and requires constant practice to learn better. , Learn faster!

请添加图片描述


代码熬夜敲
210 声望355 粉丝

李志宽、前百创作者、渗透测试专家、闷骚男一位、有自己的摇滚乐队