1、算术运算符
select 1 + 2 ;
select 1 - 2 ;
select 3 * 4 ;
select 3 / 4 ;
select 3 / 0 ;
select 3 div 4 ;
select 5 div 4 ;
2、比较运算符
mysql 比较查询结果: 0:false 1:true
作用 比较运算符 大于 > 小于 < 大于或等于 >= 小于或等于 <= 等于 = 不等于 !=,<>
select 2 > 1 ;
select 2 < 1 ;
select 3 >= 2 ;
select 3 <= 2 ;
select 1 = 1 ;
select 1 != 1 ;
select 1 <> 1 ;
比较关键字 作用 select m is true; 判断 m 是否为 true? (非 0 为真,0 为假) select m is false; 判断 m 是否为 false? select m is not true; 判断 m 是否不为 true? select m is null; 判断 m 是否为 null? select m is not null; 判断 m 是否不为 null? select x between m and n; 判断 x 是否在闭区间 [m, n] 范围内? select x not between m and n; 判断 x 是否不在闭区间 [m, n] 范围内? select x in(m,n); 聚合,判断 x 是否是(m, n) 其中一个? select x not in(m,n); 聚合,判断 x 是否不是(m, n) 其中一个?
select 4 > 5 is true ;
select 4 > 5 is false ;
select 4 > 5 is not true ;
select null is null ;
select null is not null ;
select 3 between 1 and 3 ;
select 3 not between 1 and 3 ;
select 2 in ( 1 , 2 ) ;
select 2 not in ( 1 , 2 ) ;
3、逻辑运算符
作用 比较运算符 和 and,真真为真,有假为假 或 or,假假为假,有真为真; 非 !,取相反,非真为假,非假为真。
select 1 = 1 and 1 = 2 ;
select ! 1 <> 1 ;
select 1 = 1 or 1 = 2 ;
4、位运算符
位运算符是在二进制数上进行计算的运算符。 位运算会先将操作数变成二进制数,进行位运算。然后再将计算结果从二进制数变回十进制数。
位运算有何用处呢, 例如 Linux系统中文件的权限, 通常我们所知权限分为 r 读, w 写, x 执行,其中它们的权值分别为4,2,1, 所以如果用户要想拥有这三个权限,就必须 chomd 7 , 即 7=4+2+1 表明 这个用户具有rwx权限,如果只想这个用户具有r,x权限 那么就 chomd 5即可。
运算符 作用 I 按位或 & 按位与 ^ 按位异或 << 按位左移 >> 按位右移 ~ 按位取反
select 1 | 1 ;
select 1 ^ 2 ;
select 1 & 0 ;
位运算符计算操作介绍