运算符的优先级
运算符从高到低的优先级如下所示。在同一行中的运算符优先级相等。
优先级从高到低排序 | 运算符 |
---|---|
1 | INTERVAL |
2 | BINARY, COLLATE |
3 | ! |
4 | - (unary minus), ~ (unary bit inversion) |
5 | ^ |
6 | *, /, DIV, %, MOD |
7 | -, + |
8 | <<, >> |
9 | & |
10 | | |
11 | = (comparison), <=>, >=, >, <=, <, <>, !=, IS, LIKE, , IN, MEMBER OF |
12 | BETWEEN, CASE, WHEN, THEN, ELSE |
13 | NOT |
14 | AND, && |
15 | XOR |
16 | OR, || |
17 | = (assignment) |
运算符 =
的优先级取决于它是用作比较操作符还是赋值操作符。当用作比较操作符时,它与 >=
,>
,<=
,<
,<>
,!=
,IS
,LIKE
和 IN()
具有相同的优先级。
对于在表达式中具有相同优先级的运算符,求值将从左到右进行计算,但赋值将从右到左进行计算。