1. Arithmetic operatorsMySQL supports the following arithmetic operators:
Example 1: +, -, *, /, %, mysql> select 0.1+0.333,0.1-0.333,0.1*0.333,1/2,1%2; +-----------+-----------+-----------+--------+------+ | 0.1+0.333 | 0.1-0.333 | 0.1*0.333 | 1/2 | 1%2 | +-----------+-----------+-----------+--------+------+ | 0.433 | -0.233 | 0.0333 | 0.5000 | 1 | +-----------+-----------+-----------+--------+------+ 1 row in set (0.05 sec) Example 2: In a division operation, if the divisor is mysql> select 1/0; +------+ | 1/0 | +------+ | NULL | +------+ 1 row in set (0.00 sec) Example 3: Another form of modular operation mysql> select 1%2,mod(1,2); +------+----------+ | 1%2 | mod(1,2) | +------+----------+ | 1 | 1 | +------+----------+ 1 row in set (0.00 sec) 2. Comparison OperatorsComparison operators supported by MySQL:
Example 1: " mysql> select 1<>0,1<>1,null<>null; +------+------+------------+ | 1<>0 | 1<>1 | null<>null | +------+------+------------+ | 1 | 0 | NULL | +------+------+------------+ 1 row in set (0.00 sec) Example 2: The " mysql> select 1<=>1,1<=>0,null<=>null; +-------+-------+-------------+ | 1<=>1 | 1<=>0 | null<=>null | +-------+-------+-------------+ | 1 | 0 | 1 | +-------+-------+-------------+ 1 row in set (0.02 sec) Example 3: “ mysql> select 'a'<'b','A'<'b','bdf'<'c',1<2; +---------+---------+-----------+-----+ | 'a'<'b' | 'A'<'b' | 'bdf'<'c' | 1<2 | +---------+---------+-----------+-----+ | 1 | 1 | 1 | 1 | +---------+---------+-----------+-----+ 1 row in set (0.02 sec) Example 4: mysql> select 10 between 10 and 20,9 between 10 and 20; +----------------------+---------------------+ | 10 between 10 and 20 | 9 between 10 and 20 | +----------------------+---------------------+ | 1 | 0 | +----------------------+---------------------+ 1 row in set (0.01 sec) Example 5: mysql> select 'abcdeef' regexp 'ab','abcdef' regexp 'g','abcedf' regexp 'df'; +----------------------+---------------------+----------------------+ | 'abcdeef' regexp 'ab' | 'abcdef' regexp 'g' | 'abcedf' regexp 'df' | +----------------------+---------------------+----------------------+ | 1 | 0 | 1 | +----------------------+---------------------+----------------------+ 1 row in set (0.01 sec) The rest are simple to use, so I will just give you the syntax and not write any examples.
3. Logical operatorsLogical operators in MySQL:
Example 1: ““ mysql> select not 0,!0,not 1,not null; +-------+----+-------+----------+ | not 0 | !0 | not 1 | not null | +-------+----+-------+----------+ | 1 | 1 | 0 | NULL | +-------+----+-------+----------+ 1 row in set (0.00 sec) Example 2: " mysql> select (1 and 1),(0 and 1),(3 and 1),(0 and null),(1 and null); +-----------+-----------+-----------+--------------+--------------+ | (1 and 1) | (0 and 1) | (3 and 1) | (0 and null) | (1 and null) | +-----------+-----------+-----------+--------------+--------------+ | 1 | 0 | 1 | 0 | NULL | +-----------+-----------+-----------+--------------+--------------+ 1 row in set (0.00 sec) mysql> select 1 and NULL and 0; +------------------+ | 1 and NULL and 0 | +------------------+ | 0 | +------------------+ 1 row in set (0.00 sec) mysql> select 1 and NULL and 3; +------------------+ | 1 and NULL and 3 | +------------------+ | NULL | +------------------+ 1 row in set (0.00 sec) Example 3: “ mysql> select (1 or 0),(0 or 0),(1 or NULL),(0 or NULL),(NULL or NULL); +----------+----------+-------------+-------------+----------------+ | (1 or 0) | (0 or 0) | (1 or NULL) | (0 or NULL) | (NULL or NULL) | +----------+----------+-------------+-------------+----------------+ | 1 | 0 | 1 | NULL | NULL | +----------+----------+-------------+-------------+----------------+ 1 row in set (0.00 sec) Example 4: mysql> select (0 xor 0),(1 xor 0),(1 xor 1),(1 xor null),(0 xor null),(null xor null); +-----------+-----------+-----------+--------------+--------------+----------------+ | (0 xor 0) | (1 xor 0) | (1 xor 1) | (1 xor null) | (0 xor null) | (null xor null) | +-----------+-----------+-----------+--------------+--------------+----------------+ | 0 | 1 | 0 | NULL | NULL | NULL | +-----------+-----------+-----------+--------------+--------------+----------------+ 1 row in set (0.00 sec) 4. Bitwise operatorsMySQL supports the following bitwise operators:
Example 1: “Bitwise AND” performs a logical AND operation on the binary bits of multiple operands. 2&3, the binary number of 2 is 10, and the binary number of 3 is 11. If we do the AND operation, the result is still 10, and the result converted to decimal is 2 mysql> select 2&3; +-----+ | 2&3 | +-----+ | 2 | +-----+ 1 row in set (0.01 sec) Example 2: “Bitwise OR” performs a logical OR operation on the binary bits of multiple operands. 2&3, the binary number of 2 is 10, and the binary number of 3 is 11. When we do the AND operation, the result becomes 11, and the result converted to decimal is 3 mysql> select 2|3; +-----+ | 2|3 | +-----+ | 3 | +-----+ 1 row in set (0.00 sec) Example 3: “ mysql> select 2^3; +-----+ | 2^3 | +-----+ | 1 | +-----+ 1 row in set (0.01 sec) Example 4: "Bitwise inversion" performs a NOT operation on the binary bit of the operand. Here, the operand can only be one bit. Explanation: In MySQL, the constant number is represented by 8 bytes by default, and 8 bytes is 64 bits. The binary of the constant 1 is 63 0s and 1 1. After bitwise inversion, it is 63 1s and 1 0. After conversion to binary, it is 18446744073709551614. mysql> select ~1,~18446744073709551614 -> ; +----------------------+-----------------------+ | ~1 | ~18446744073709551614 | +----------------------+-----------------------+ | 18446744073709551614 | 1 | +----------------------+-----------------------+ 1 row in set (0.01 sec) mysql> select bin(18446744073709551614); +----------------------------------------------------------------------------------+ | bin(18446744073709551614) | +----------------------------------------------------------------------------------+ | 1111111111111111111111111111111111111111111111111111111111110 | +----------------------------------------------------------------------------------+ 1 row in set (0.03 sec) Example 5: “Bit right shift” moves the left operand to the right by the number of bits specified by the operand. For example, 100>>3, the binary number of 100 0001100100 is shifted right by 3 bits, 0000001100, which is converted to 12 in binary: mysql> select 100>>3; +--------+ | 100>>3 | +--------+ | 12 | +--------+ 1 row in set (0.00 sec) Example 6: “Bitwise Left Shift” shifts the left operand to the left by the number of bits specified by the operand. For example, 100<<3, the binary number of 100 0001100100000 is shifted right by 3 bits, 1100100000000, which is converted to binary number 800: mysql> select 100<<3; +--------+ | 100<<3 | +--------+ | 800 | +--------+ 1 row in set (0.00 sec) 5. Operator precedenceOperator precedence in MySQL:
This is the end of this article about the summary of MYSQL operators. For more relevant MYSQL operator content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: 30 free high-quality English ribbon fonts
>>: JavaScript realizes the drag effect of modal box
Table of contents 1. Docker installation on Mac 2...
Preface MySQL continued to maintain its strong gr...
When server B (172.17.166.11) is powered on or re...
Before reading this article, I hope you have a ba...
Volume Label, Property Name, Description 002 <...
Recently, there is a need to automatically search...
For a long time, website development was hampered...
What is a primary key? A primary key is a column ...
Table of contents join algorithm The difference b...
There are probably as many modular solutions for ...
@Font-face basic introduction: @font-face is a CSS...
Here are the detailed steps: 1. Check the disk sp...
This is what happened. Today I was playing with G...
I was curious about how to access the project usi...
1. Dynamic query rules The dynamic query rules ar...