mysql where查询_MySQL之where的条件查询

各位小伙伴们大家好,好久不见哈,在之前的文章中,小编介绍了一些数据库的相关知识,这次小编要介绍的是MySQL当中的条件查询。

条件查询:where子句后跟条件。

首先,我们需要了解一些运算符。

>,=,=.<>(不等于)between......andin(集合)likeis nulland 或者 &&or 或 ||not 或 !我们要查询这张学生表里的内容:

c92a6e3a8f2edd8fb1f66b0dcbe4eedd.png

查询年龄大于20的学生:

select * from student1 where age>20;

9112d14fe67072c35058fa7634bda8fa.png

查询年龄大于等于20的人:

select * from student1 where age>=20;

依此类推,如果要查询年龄小于或者小于等于或者等于多少岁,改变一下运算符和数字就好了。小编就不一一演示了。(注意等于写一个等号就可以了)。

查询年龄不等于20岁:

select * from student1 where age !=20;

也可以用这种方式:select * from student1 where age <> 20;

查询结果:

c6010033a0bfd96aae0bcba5abda262d.png

查询在年龄大于等于18,小于等于20之间的人:

方法1:select * from student1 where age>=18 && age<=20;

方法2:select * from student1 where age>=18 and age<=20;

方法3:select * from student1 where age between 18 and 20;

查询年龄16,18,19的学生信息:

方法1:select * from student1 where age=16 or age=18 or age=19;

方法2:select * from student1 where age in(16,18,19);

查询数学成绩为null的学

生信息:select * from student1 where math is null;

6aa96e01ffb1ebfc61036ce6a5c01667.png

结果为空,说明表里的学生都有数学成绩。

查询数学成绩不为空的学生信息:select * from student1 where math is not null;

关于MySQL中where的条件查询,小编就先说到这里,很简单的条件查询,只是where后面加条件,然后再简单的翻译一下英语,去理解就好了。希望这篇文章可以帮到大家,也欢迎各位小伙伴补充和纠错。接下来的文章中小编会讲模糊查询(like)

关于MySQL小编讲的比较跳,前期的一些基础知识,小伙伴们需要自行去了解,小编在之后的文章中也会做相关补充。

d4349b7f634509b83477295f43ab0534.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值