MySQL之where查询


比较运算
只显示id,name:     select id,name from students;
消除重复行distinct
select distinct gender from students;
条件
select * from students where id>3;
select * from students where isDelete=0;
逻辑运算
  • and
  • or
  • not
select * from students where id>3 and gender=0;
select * from students where id<4 or isDelete=0;
模糊查询
  • like
  • % : 表示任意多个字符
  • _ : 表示一个任意字符

查询姓罗的人:

select * from students where name like '罗%';

查询姓杨 且 名字是一个字的人:

select * from students where name like '杨_';

查询姓薛 且 名字两个字的人:

select * from students where name like '薛__';

查询姓罗 或者 叫嫣 的人:

select * from students where name like '罗%' or name like '%嫣';
范围查询
  • in :表示在一个非连续的范围内
  • 查询编号是1或3或8的人
select * from students where id in(1,3,8);
  • between ... and ... 表示在一个连续的范围内(between后小数,and后大数)
  • 查询id是3到8的人
select * from students where id between 3 and 8;

select * from students where id between 3 and 8and gender=1;

空判断
  • null与''不相同
  • 判断: is null
select * from students where birthday is null;
select * from students where birthday is not null;
优先级
  • 小括号, not, 比较运算符, 逻辑运算符
  • and比or先运算,如果同时出现并希望先算or,需要结合()使用



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值