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

How does MySQL operator precedence affect result sets?

王林
Release: 2023-09-14 09:13:08
forward
830 people have browsed it

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
:=
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template