MySQL学习笔记(5)--运算符

·算术运算符

通常用于结果运算(select 字段中)

create table my_int(
    a int,
    b int,
    c int,
    d int 
);
insert into my_int values(1,-1,0,default);
select a + b, a - b, a * b, a / b, a / c, d / b from my_int;
--分母为0时结果是NULL,NULL进行任何计算结果都是NULL

·比较运算符

‘> >= < <= = <>(不等于)’
=:在MySQL中没有==,也可以用<=>来比较
特殊应用:在字段结果在进行比较运行

select '1' <=> 1, 0.02 <=> 0, 0.02 <> 0;

在这里插入图片描述
在条件判断的时候还有对应的比较计算符:区间

between 条件1 and 条件2   --闭区间查找,条件1必须小于条件2,反过来查不到信息
--实例
select * from my_student where stu_age between 20 and 30; 

·逻辑运算符

1. and与 or或 not非

select * from my_student where stu_age >= 20 and stu_age <= 30;  --结果同上

2. ·in
用来替代 = ,当结果不是一个值,而是结果集的时候

in(结果1, 结果2....)
--实例
select * from my_student where stu_id in ('stu001','stu002');

3. is

is null / is not null
--实例
select * from my_int where d = null;  --没有结果,因为null进行任何运算结果都是null
select * from my_int where d is null;  --成功

专用于判断字段是否为NULL
4. like
用于模糊匹配, 用到 _ 和 %

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值