sql语句
一、数据库的增删改查
- 查询语句------select 查询内容(*代表任意) from 表名 where 查询条件;
- 更新数据------update 表名 set 列1=值1,列2=值2... (where 条件)
- 增加数据-----insert into 表明 values(...) \ insert into 表名(列1,...) values (值1,...)
- 删除数据-----delete from 表名 where 条件
二、数据库的条件
- 条件查询---比较运算符:等于=、大于>
- 逻辑运算--and or not
- 模糊查询--like 如 where name like '马%';
- 范围查询--in(非连续范围内)、between … and …(一个连续的范围内)
- 为空判断--is not null 如 where sex is not null;
三、查询结果
- 排序--order by 字段 desc(desc降序、asc);
- 分组--group by 字段;
- 分页--limit start=0,count 或 xxx limit n(前n条数据);
四、聚合函数
- 总数--count(*),如select count(*) from students;
- 最大最小值--max\min ,如select max(score) from student_score;
- 求和--sum,如select sum(age) from students;
- 列的平均值--avg(列),如 select avg(id) from students where is_delete=0 and gender=2;
- group by +having过滤: