select * from 表名;
1.语法:
select
字段列表
from
表名列表
where
条件列表
group by
分组字段
having
分组之后的条件
order by
排序
limit
分页限定
2.基础查询
1.多个字段的查询
select 字段名1,字段名2,...from 表名;
注意:
如果查询所有字段,则可以使用*来代替字段列表
2.去除重复
distinct
3.计算列
一般可以使用四则运算计算一些列的值。(一般只会进行数值型的计算)
ifnull(表达式1,表达式2):null参与的运算,计算结果都为null
表达式1:哪个字段需要判断是否为null
表达式2:如果该字段为null后的替换值
4.起别名
as:as也可以省略
3.条件查询
1.where子句后跟条件
2.运算符
and 或 &&
&nbs***bsp;或 ||
not 或 !
> 、< 、<= 、>= 、= 、<>
-- 查询年龄不等于20岁的人
select * from xx where sge <> 20;
between...end
-- 查询年龄大于等于20 小于等于30 的人
select * from xx where sge between 20 and 30;
in(集合)
-- 查询年龄为22岁,18岁,45岁的信息
select * from xx where sge in (11,18,45);
like
占位符:
_:单个任意字符
%:多个任意字符
-- 查询姓马的有哪些
select * from xx where name like '马%';
-- 查询姓名第二个字是马的人
select * from xx where name like '_马%';
-- 查询姓名是三个字的人
select * from xx where name like '___';
--查询姓名中包含马的人
select * from xx where name like '%马%';
is null
-- 查询英语成绩为null
select * from xx where English is null;