运算符分类
MySQL中支持的运算符主要分为4种,分别为算术运算符,比较运算符,逻辑运算符,位运算符
算术运算符
# 主要包括+、 -、 *、 /、 div
1. select 1+1; # 2
2. select 1-1; # 0
3. select 1*2; # 2
4. select 3/2; # 1.5
5. select 3 div 2; # 1(整除)
6. select 3/0; # null
比较运算符
# 主要包括>、 <、 >=、 <=、 !=、 beteween...and...、 in、 not in、 is null、 is not null
1. select 5>3; # 1
2. select 5<3; # 0
3. is null/is not null
select * from student_scores where name is null;
4. select * from student_scores where score between 60 and 80; # 表示介于60到80之间的成绩,包括60和80
逻辑运算符
# 主要包括 and or !
1. select 1=2 and 1=1; # 0
2. select 1=2 and 1=1; # 1
3. select !1 = 1; #0
位运算符
# 主要包括 |、 & 、 ^
1. select 3 & 2; # 2
2. select 3 | 2; # 3
3. select 3 ^ 2; # 1