mysql主要有算数运算符、比较运算符、逻辑运算符、位运算符
1、算数运算符
+ select 1+2;
- select 1-2;
* select 1* 2;
/ 或div select 1/2; or select 1 div 2;
% 或 mod select 1%2; or select 1 mod 2;
2、比较运算符
= select 2=3;
<> != select 2<>3;
> select 2>3;
< select 2<3;
<= select 2<=3;
>= select 2>=3
between select 5 between 0 and 10;
not between select 5 not between 0 and 10;
in select 5 in (1,2,3,4,5)
not in select 5 not in (1,2,3,4,5)
<=> 严格比较两个null值是否相等,两个操作码均为null时,值为1,当一个操作码为null时,值为0 select 1<=>2 ;select null<=>null;
like select '123456' like '12%';
is null select null is null;
is not null select 'a' is not null;
regexp 或rlike 正则式匹配 select 'beijing' regexp 'jing';
3、逻辑运算符
not ! and or xor
select 2 and 0;
select 2and 1;
select 2 or 0;
select 2 or 1;
select not 1;
select !0;
select 1 xor 1;
4、位运算符
& | ^ ! << >>
1、按位与
mysql>select3&5;+-----+|3&5|+-----+|1|+-----+
2、按位或
mysql>select3|5;+-----+|3|5|+-----+|7|+-----+
3、按位异或
mysql>select3^5;+-----+|3^5|+-----+|6|+-----+
4、按位取反
mysql>select~18446744073709551612;+-----------------------+|~18446744073709551612|+-----------------------+|3|+-----------------------+
5、按位右移
mysql>select3>>1;+------+|3>>1|+------+|1|+------+
6、按位左移
mysql>select3<<1;+------+|3<<1|+------+|6|+------+
运算符优先级
最低优先级为: :=。
最高优先级为: !、BINARY、 COLLATE。