Home  >  Article  >  Database  >  How does MySQL operator precedence affect result sets?

How does MySQL operator precedence affect result sets?

王林
王林forward
2023-09-14 09:13:08744browse

MySQL 运算符优先级如何影响结果集?

MySQL follows operator precedence, it has the following list of operators, with the same precedence and on the same line -

INTERVAL
BINARY, COLLATE
!
- (unary minus), ~ (unary bit inversion)
^
*, /, DIV, %, MOD
-, +
<<, >>
&
|
=, <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, IN
BETWEEN, CASE, WHEN, THEN, ELSE
NOT
&&, AND
XOR
||, OR
:=

for expressions Operators of the same precedence are evaluated from left to right.

Example

The following example shows operator precedence versus result set -

mysql> Select 5+3/2-2;
+---------+
| 5+3/2-2 |
+---------+
| 4.5000  |
+---------+
1 row in set (0.00 sec)

In the above calculation, MySQL calculates /(div) first because of its Priority is higher than (addition) or – (subtraction).

The above is the detailed content of How does MySQL operator precedence affect result sets?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete