preface
@TOC This article discusses the various operators used in SQL in the following order:
This article discusses the various operators used in SQL in the following order:
- What is an operator?
- Classification of operators:
Arithmetic operator Comparison operator Logic operator
What is an operator?
SQL operators are reserved keys used to perform arithmetic, logical, and comparison operations in the WHERE clause of AN SQL statement. Operators act as concatenators in SQL statements to satisfy multiple conditions in the statement.
Classification of operators:
Arithmetic operator
These operators are used to perform addition, multiplication, subtraction, etc.
Example:
SELECT 40 + 20;
SELECT 40 - 20;
SELECT 40 * 20;
SELECT 40 / 20;
SELECT 40 % 20;
Copy the code
Output:
60, 20, 800, 2, 0Copy the code
Comparison operator
These operators are used to perform equal, greater than, less than, and so on.
Example:
To better understand, I’ll consider the following table to perform various operations.
Example (equal to) :
SELECT * FROM Students
WHERE Age = 20;
Copy the code
Output:
Examples (greater than) :
SELECT * FROM students
WHERE Age > 23;
Copy the code
Output:
Example (less than or equal to) :
SELECT * FROM students
WHERE Age <= 21;
Copy the code
Output:
Example (not equal to) :
SELECT * FROM students
WHERE Age <> 25;
Copy the code
Output:
Logical operator
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);
Copy the code
Output:Examples (BETWEEN & AND)
SELECT * FROM Students
WHERE Age BETWEEN 22 AND 25;
Copy the code
Output:
Example (IN)
SELECT * FROM Students
WHERE Age IN('23', '20');
Copy the code
Output:
In this article, I just cited the most common but example, of course, database and network technology is not quite the same, the network has a lot of original things, but the database is biased to actual combat, need constant practice to learn better, learn faster!