小粥重学mysql(4)之DCL(数据库查询语言)----条件查询
运算符
比较运算符 | 说明 |
---|
>、<、<=、>=、=、<> | <>在SQL中表示不等于,mysql中可使用!=,但没有== |
between…and | 在…范围内,between 100 and 200 相当于100到200之间,包头包尾 |
in(集合) | 集合表示多个值,逗号分割 |
like ‘张%’ | 模糊查询 _(下划线):单个任意字符;%:多个任意字符 |
is null | 查询某列为null的值,不能使用=null |
逻辑运算符 | 说明 |
---|
and 或 && | 与(&&不通用) |
or 或 || | 或 |
not 或 ! | 非 |
select * from stu where age >=20
select * from stu where age != 20
select * from stu where age <> 20
select * from stu where age>=20 and age <=30
select * from stu where age between 20 and 30
# 查询年龄22岁,19岁,25岁的学生
select * from stu where age = 22 or age = 19 or age = 25
select * from stu where age in (22,19,25)
select * from stu where english is null
select * from stu where english is not null
select * from stu where name like '马%'
select * from stu where name like "_化%"
select * from stu where name like "___"
select * from stu where name like "%马%"