语法:
select 数据列表 from where 筛选条件
筛选条件
1.条件运算符
> : 左边 大于 右边
< : 左边 小于 右边
= : 左边 等于 右边
!= : 左边 不等于 右边
<> : 左边 不等于 右边
>= : 左边 大于或者等于 右边
<= : 左边 小于或者等于 右边
<=> : 安全等于;可以判断null,与其他类型
案例:
select * from user where username="王麻子";
2.逻辑运算符
&&/and : 两边的条件 成立
||/or : 两边的条件 有一个成立
!/not : 将成立改为不成立 , 不成立改为成立
案例:
select * from user username='王麻子' and age=12
3.模糊查询
- like
% : 模糊查询
_ : 匹配任意一个字符
案例:
select * from user username like '_麻%'; //查询第二个字为 '麻' 的数据
- between and
在什么什么之间
注意:
- 必须是有小到大; 例如:10-20; 但是:20-10是不可以的
案例:
//查询age 10到20之间的数据
select * from User age between 10 and 20;
in:
判断某个字段的值是否符合in参数中的任意一个
案例:
select * from user age=10 or age =20
==
select * from User age in(10,20)
is null:
判断是否为空
案例:
//查询所有username字段为空的数据
select * from user where username is null;
is not null:
判断是否不为空
案例:
//查询所有username字段不为空的数据
select * from user where username is not null;