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!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。