### 12.4.1 运算符优先级 [](<>)[](<>) 运算符优先级显示在以下列表中,从最高优先级到最低优先级。在一行中一起显示的运算符具有相同的优先级。 ``` 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), := ``` 的优先级`=`取决于它是否用作比较运算符 ([`=`](comparison-operators.html#operator_equal)) 或作为赋值运算符 ([`=`](assignment-operators.html#operator_assign-equal))。当用作比较运算符时,它的优先级与[`<=>`](comparison-operators.html#operator_equal-to),[`>=`](comparison-operators.html#operator_greater-than-or-equal),[`>`](comparison-operators.html#operator_greater-than),[`<=`](comparison-operators.html#operator_less-than-or-equal),[`<`](comparison-operators.html#operator_less-than),[`<>`](comparison-operators.html#operator_not-equal),[`!=`](comparison-operators.html#operator_not-equal),[`是`](comparison-operators.html#operator_is),[`喜欢`](string-comparison-functions.html#operator_like),[`正则表达式`](regexp.html#operator_regexp), 和[`在()`](comparison-operators.html#operator_in).当用作赋值运算符时,它的优先级与[`:=`](assignment-operators.html#operator_assign-value).[第 13.7.6.1 节,“变量赋值的 SET 语法”](set-variable.html), 和[第 9.4 节,“用户定义的变量”](user-variables.html),解释一下MySQL是如何决定哪个解释的`=`应该申请。 对于在表达式中以相同优先级出现的运算符,求值从左到右进行,但赋值从右到左求值的例外。 某些运算符的优先级和含义取决于 SQL 模式: - 默认,[`||`](logical-operators.html#operator_or)是一个合乎逻辑的[`要么`](logical-operators.html#operator_or)操作员。和[`PIPES_AS_CONCAT`](sql-mode.html#sqlmode_pipes_as_concat)启用,[`||`](logical-operators.html#operator_or)是字符串连接,优先级在[`^`](bit-functions.html#operator_bitwise-xor)和一元运算符。 - 默认,[`!`](logical-operators.html#operator_not)优先级高于`不是`.和[`HIGH_NOT_PRECEDENCE`](sql-mode.html#sqlmode_high_not_precedence)启用,[`!`](logical-operators.html#operator_not)和`不是`具有相同的优先级。 看[第 5.1.11 节,“服务器 SQL 模式”](sql-mode.html). [](<>)[](<>)[](<>)[](<>) 运算符的优先级决定了表达式中项的计算顺序。要显式覆盖此顺序和组术语,请使用括号。例如: ``` mysql> SELECT 1+2*3; -> 7 mysql> SELECT (1+2)*3; -> 9 ```