Operator precedences are shown in the following list, from highest precedence to the lowest. 运算符优先顺序显示在下面的列表中,从最高优先顺序到最低优先顺序。Operators that are shown together on a line have the same precedence.在一行上同时显示的运算符具有相同的优先级。
INTERVAL BINARY, COLLATE ! - (unary minus), ~ (unary bit inversion) ^ *, /, DIV, %, MOD -, + <<, >> & | = (comparison), <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, IN, MEMBER OF BETWEEN, CASE, WHEN, THEN, ELSE NOT AND, && XOR OR, || = (assignment), :=
The precedence of =
depends on whether it is used as a comparison operator (=
) or as an assignment operator (=
). =
的优先级取决于它是用作比较运算符(=
)还是用作赋值运算符(=
)。When used as a comparison operator, it has the same precedence as 当用作比较运算符时,它的优先级与<=>
, >=
, >
, <=
, <
, <>
, !=
, IS
, LIKE
, REGEXP
, and IN()
. <=>
、>=
、>
、<=
、<
、<>
,!=
,IS
,LIKE
、REGEXP
和IN()
相同。When used as an assignment operator, it has the same precedence as 当用作赋值运算符时,它的优先级与:=
. :=
相同。Section 13.7.6.1, “SET Syntax for Variable Assignment”, and Section 9.4, “User-Defined Variables”, explain how MySQL determines which interpretation of 第13.7.6.1节,“变量赋值的设置语法”和第9.4节,“用户定义变量”解释了MySQL如何确定=
should apply.=
所应用的解读。
For operators that occur at the same precedence level within an expression, evaluation proceeds left to right, with the exception that assignments evaluate right to left.对于表达式中出现在同一优先级的运算符,求值从左到右进行,但赋值从右到左求值除外。
The precedence and meaning of some operators depends on the SQL mode:某些运算符的优先级和含义取决于SQL模式:
By default, 默认情况下,||
is a logical OR
operator. ||
是逻辑或运算符。With PIPES_AS_CONCAT
enabled, ||
is string concatenation, with a precedence between ^
and the unary operators.PIPES_AS_CONCAT
启用时,||
是字符串串联,具有在^
和一元运算符之间的优先级。
By default, 默认情况下!
has a higher precedence than NOT
. !
具有比NOT
更高的优先级。With HIGH_NOT_PRECEDENCE
enabled, !
and NOT
have the same precedence.HIGH_NOT_PRECEDENCE
启用时,!
和NOT
具有同样的优先级。
See Section 5.1.11, “Server SQL Modes”.请参阅第5.1.11节,“服务器SQL模式”。
The precedence of operators determines the order of evaluation of terms in an expression. 运算符的优先级决定表达式中术语的求值顺序。To override this order and group terms explicitly, use parentheses. 要显式重写此顺序和组术语,请使用括号。For example:例如:
mysql>SELECT 1+2*3;
-> 7 mysql>SELECT (1+2)*3;
-> 9