当前位置:Gxlcms > mysql > MySQL管理与优化(3)_MySQL

MySQL管理与优化(3)_MySQL

时间:2021-07-01 10:21:17 帮助过:22人阅读

运算符

算术运算符:

  • 运算符有+, -, *, %(mod函数), /(div函数)。

比较运算符:

  • 数字作为浮点数比较,字符串以不区分大小写的方式进行比较。

mysql> SELECT 10 BETWEEN 10 AND 20, 9 BETWEEN 10 AND 20;+----------------------+---------------------+| 10 BETWEEN 10 AND 20 | 9 BETWEEN 10 AND 20 |+----------------------+---------------------+|                    1 |                   0 |+----------------------+---------------------+

  • regexp则用正则表达式进行匹配,如:
mysql> SELECT 'abcdef' regexp 'ab', 'abcdefg' regexp 'k';+----------------------+----------------------+| 'abcdef' regexp 'ab' | 'abcdefg' regexp 'k' |+----------------------+----------------------+|                    1 |                    0 |+----------------------+----------------------+

逻辑运算符:

MySQL中包含的逻辑运算符:

分别对几种逻辑运算符进行描述:

mysql> SELECT NOT 0, NOT 1 , NOT NULL;+-------+-------+----------+| NOT 0 | NOT 1 | NOT NULL |+-------+-------+----------+|     1 |     0 |     NULL |+-------+-------+----------+   

mysql> SELECT 1 AND 1, 0 AND 1, 3 AND 1, 1 AND NULL;+---------+---------+---------+------------+| 1 AND 1 | 0 AND 1 | 3 AND 1 | 1 AND NULL |+---------+---------+---------+------------+|       1 |       0 |       1 |       NULL |+---------+---------+---------+------------+
mysql> SELECT 1 OR 0, 0 OR 0, 1 OR NULL, 1 OR 1, NULL OR NULL;+--------+--------+-----------+--------+--------------+| 1 OR 0 | 0 OR 0 | 1 OR NULL | 1 OR 1 | NULL OR NULL |+--------+--------+-----------+--------+--------------+|      1 |      0 |         1 |      1 |         NULL |+--------+--------+-----------+--------+--------------+
mysql> SELECT 1 XOR 1, 0 XOR 0, 1 XOR 0, 0 XOR 1, NULL XOR 1;+---------+---------+---------+---------+------------+| 1 XOR 1 | 0 XOR 0 | 1 XOR 0 | 0 XOR 1 | NULL XOR 1 |+---------+---------+---------+---------+------------+|       0 |       0 |       1 |       1 |       NULL |+---------+---------+---------+---------+------------+

位运算符:

MySQL5.0支持的位运算符:

分别介绍这几种位运算:

mysql> SELECT 2&3, 2&3&4;+-----+-------+| 2&3 | 2&3&4 |+-----+-------+|   2 |     0 |+-----+-------+
mysql> SELECT 2|3, 2|3|4;+-----+-------+| 2|3 | 2|3|4 |+-----+-------+|   3 |     7 |+-----+-------+
mysql> SELECT 2^3;+-----+| 2^3 |+-----+|   1 |+-----+
mysql> SELECT ~1, ~18446744073709551614;+----------------------+-----------------------+| ~1                   | ~18446744073709551614 |+----------------------+-----------------------+| 18446744073709551614 |                     1 |+----------------------+-----------------------+
mysql> SELECT 100>>3;+--------+| 100>>3 |+--------+|     12 |+--------+
mysql> SELECT 100<<3;+--------+| 100<<3 |+--------+|    800 |+--------+

运算符的优先级:

具体的运算符的细节可参考官网:

http://dev.mysql.com/doc/refman/5.7/en/non-typed-operators.html

不吝指正。

人气教程排行