📜  SQL 运算符

📅  最后修改于: 2022-05-13 01:54:18.570000             🧑  作者: Mango

SQL 运算符

运算符是任何编程语言的基础。我们可以将运算符定义为帮助我们对操作数执行特定数学和逻辑计算的符号。换句话说,我们可以说运算符操作操作数。 SQL运算符具有三个不同的类别。

  • 算术运算运算符
  • 运算符
  • 逻辑运算符

算术运算运算符

我们可以对存储在表中的数据使用各种算术运算运算符。算术运算符是:

S.No.OperatorDescription
1+

The addition is used to perform an addition operation on the data values.

2

This operator is used for the subtraction of the data values.

3/

This operator works with the ‘ALL’ keyword and it calculates division operations.



4*

This operator is used for multiply data values.

5%

Modulus is used to get the remainder when data is divided by another.

运算符

在SQL的另一个重要运算符是比较运算符,它用于将一个表达式的值比其他表达式。 SQL支持不同类型的比较运算符,这将在下面描述的:

S.No.OperatorDescription
1=Equal to.
2>Greater than.
3<Less than.
4>=Greater than equal to.
5<=Less than equal to.
6<>Not equal to.

逻辑运算符:

逻辑运算符是真或假的运算符。它们返回 true 或 false 值以组合一个或多个 true 或 false 值。

S.NoOperatorDescription
1AND

Logical AND compares between two Booleans as expressions and returns true when both expressions are true.

2OR

Logical OR compares between two Booleans as expressions and returns true when one of the expressions is true.

3NOT

Not takes a single Boolean as an argument and changes its value from false to true or from true to false.

特殊运算符:

S.No.OperatorDescription 
1ALL 

ALL is used to select all records of a SELECT STATEMENT. It compares a value to every value in a list ofof results from a query. The ALL must be preceded by the comparison operators and evaluates to TRUE if the query returns no rows.

2ANY

ANY compares a value to each value in a list of results from a query and evaluates to true if the result of an inner query contains at least one row.

3BETWEEN

The SQL BETWEEN operator tests an expression against a range. The range consists of a beginning, followed by an AND keyword and an end expression.

4IN

The IN operator checks a value within a set of values separated by commas and retrieves the rows from the table which are matching.

5EXISTS

The EXISTS checks the existence of a result of a subquery. The EXISTS subquery tests whether a subquery fetches at least one row. When no data is returned then this operator returns ‘FALSE’.  

6SOMESOME operator evaluates the condition between the outer and inner tables and evaluates to true if the final result returns any one row. If not, then it evaluates to false.