-- 查找
select id,name,sex,age from student
select * from student
-- 添加
insert into student(name,age,sex) values("吴十",26,"女")
-- 修改
update student set name="吴千",age=29,sex="男" where id = 8
-- 删除
delete from student where id = 8
select * from student where age > 20
select * from student where sex = "男"
-- = 等于
-- > 大于
-- < 小于
-- <= 小于等于
-- >= 大于等于
-- != <> 不等于
select * from student where age >= 20 and age <= 30
-- 逻辑运算符
-- and 并且
-- or 或者
select * from student where age between 20 and 30
select * from student where id in(1,4,6)
-- select * from student where age =34 or age = 20 or age = 19 or age = 22
-- between .. and .. 两个值之间 [20,30]
-- in 包含
select * from student where age is null
-- is null 为null
-- 模糊查询
-- like 为模糊查询,需要配合占位符使用
-- _代表一位字符
-- %代表任意位字符
select * from student where name like "%张%"
select * from student limit 3 offset 0
select * from student limit 0,3
-- 分页查询(限制查询)
-- limit a,b 限制查询子语句 a代表起始索引值,起始索引值从0开始 b查询个数
-- limit b offset a
-- 如果有其他子语句,limit子语句放在最后位置
-- 排序
-- order by 列名 desc降序|asc升序 (默认升序,asc可以省略)
-- 排序子语句的相对位置在where子语句之后,在limit子语句之前
select * from student order by age limit 0,3
-- 聚合函数/分组函数
-- sum求和
-- avg 取平均
-- max 取最大值
-- min 取最小值
-- count 取得记录数 不会统计值为null的记录
-- group by字段名称
-- 分组之后筛选用having
select avg(age),class from student where sex="男" group by class having class=1