+,-,*,/(DIV),%(MOD)
select 1 + 2;
select 1 - 2;
select 1 * 2;
select 2 / 3;
mysql> select 2/3;
+--------+
| 2/3 |
+--------+
| 0.6667 |
+--------+
select 10 DIV 4;
mysql> select 10 DIV 4;
+----------+
| 10 DIV 4 |
+----------+
| 2 |
+----------+
select 10 MOD 4;
mysql> select 10 MOD 4;
+----------+
| 10 DIV 4 |
+----------+
| 2 |
+----------+
比较运算符
mysql> select 2=3; // 0
mysql> select NULL = NULL; // NULL
mysql> select 2<>3; // 1
### 安全等于, 与 = 的区别在于当两个操作码均为 NULL 时,其所得值为 1 而不为 NULL,
### 而当一个操作码为 NULL 时,其所得值为 0而不为 NULL。
mysql> select 2<=>3; // 0 // 安全等于
mysql> select 2<3; // 1
mysql> select 2<=3; // 1
mysql> select 2>3; // 0
mysql> select 2>=3; // 0
mysql> select 5 between 1 and 10; // 什么到什么之间
+--------------------+
| 5 between 1 and 10 |
+--------------------+
| 1 |
+--------------------+
mysql> select 5 in (1,2,3,4,5); // 在集合中
+------------------+
| 5 in (1,2,3,4,5) |
+------------------+
| 1 |
+------------------+
mysql> select 5 not in (1,2,3,4,5); // 不在集合中
+----------------------+
| 5 not in (1,2,3,4,5) |
+----------------------+
| 0 |
+----------------------+
mysql> select null is NULL;
+--------------+
| null is NULL |
+--------------+
| 1 |
+--------------+
mysql> select 'a' is NULL;
+-------------+
| 'a' is NULL |
+-------------+
| 0 |
+-------------+
mysql> select null IS NOT NULL;
+------------------+
| null IS NOT NULL |
+------------------+
| 0 |
+------------------+
mysql> select 'a' IS NOT NULL;
+-----------------+
| 'a' IS NOT NULL |
+-----------------+
| 1 |
+-----------------+
mysql> select '12345' like '12%';
+--------------------+
| '12345' like '12%' |
+--------------------+
| 1 |
+--------------------+
mysql> select '12345' like '12_';
+--------------------+
| '12345' like '12_' |
+--------------------+
| 0 |
+--------------------+
mysql> select 'beijing' REGEXP 'jing';
+-------------------------+
| 'beijing' REGEXP 'jing' |
+-------------------------+
| 1 |
+-------------------------+
mysql> select 'beijing' REGEXP 'xi';
+-----------------------+
| 'beijing' REGEXP 'xi' |
+-----------------------+
| 0 |
+-----------------------+
逻辑运算符
mysql> select 2 and 0;
+---------+
| 2 and 0 |
+---------+
| 0 |
+---------+
mysql> select 2 and 1;
+---------+
| 2 and 1 |
+---------+
| 1 |
+---------+
mysql> select 2 or 0;
+--------+
| 2 or 0 |
+--------+
| 1 |
+--------+
mysql> select 2 or 1;
+--------+
| 2 or 1 |
+--------+
| 1 |
+--------+
mysql> select 0 or 0;
+--------+
| 0 or 0 |
+--------+
| 0 |
+--------+
mysql> select 1 || 0;
+--------+
| 1 || 0 |
+--------+
| 1 |
+--------+
mysql> select not 1;
+-------+
| not 1 |
+-------+
| 0 |
+-------+
mysql> select !0;
+----+
| !0 |
+----+
| 1 |
+----+
## 异或
mysql> select 1 xor 1;
+---------+
| 1 xor 1 |
+---------+
| 0 |
+---------+
mysql> select 0 xor 0;
+---------+
| 0 xor 0 |
+---------+
| 0 |
+---------+
mysql> select 1 xor 0;
+---------+
| 1 xor 0 |
+---------+
| 1 |
+---------+
mysql> select null or 1;
+-----------+
| null or 1 |
+-----------+
| 1 |
+-----------+
mysql> select 1 ^ 0;
+-------+
| 1 ^ 0 |
+-------+
| 1 |
+-------+
运算符优先级
最低优先级为: :=。
最高优先级为: !、BINARY、 COLLATE。