增加数据· 添加单行数据o insertinto表名 values(值1,值2,值3,值4);o insertinto表名(字段名1,字段名2)values(值1,值2,值3,值4);· 添加多行数据o insertinto 表名 values(值1,值2,值3,值4),(值1,值2,值3,值4);o insertinto 表名(字段名1,字段名2) values(值1,值2,值3,值4),(值1,值2,值3,值4);更新数据· update表名 set 字段1=值,字段2=值 where 条件删除数据· 语法1o deletefrom 表名 where 条件· 语法2o truncatetable 表名· 语法3o droptable 表名· 速度上 drop > truncate >delete查询数据· 基础查询o select*from 表名· 查询部分字段o select字段名1,字段名2from 表明· 起别名o select别名.字段名1,别名.字段名2 from 表名 as 别名· 去重o selectdistinct 字段名1,字段名2 from 表名· 条件查询o select* from 表名 where 条件o 支持条件运算符和逻辑运算符· 模糊查询o 条件格式:字段like值o %表示任意多个任意字符o _表示一个任意字符· 范围查询o in表示在一个非连续的范围内· 空判断o null才是空o ''是空字符串o 字段是null· 排序o 默认按照列值从小到大排序o asc从小到大排列,即升序o desc从大到小 即降序· 聚合数据o 为了快速得到统计数据,用到5个聚合函数count,max,min,avg,sum· 分组o select字段1,字段2,聚合函数 from 表明group by 字段1,字段2o 分组后筛选select 字段1,字段2,聚合函数 from 表明 group by 字段1,字段2 having 条件· where和having的对比o where是对from后面指定的表进行数据筛选,属于最原始数据的筛选o having是对group by的结果进行筛选o having后面的条件中可以用聚合函数,where后面不可以· 获取部分行o select*from 表名 limit 起始位置,数量o 起始位置:是索引 从0开始· 连接查询o 内连接select * from 表1inner join 表2 on 连接条件inner join 表3 on 连接条件§ 拓展写法· select* from 表1,表2 where 连接条件o 左连接select * from 表1left join 表2 on 连接条件left join 表3 on 连接条件§ 查询的结果为==两个表匹配到的数据加左表特有的数据==,对于右表中不存在的数据使用nulo 右连接select * from 表1right join 表2 on 连接条件right join 表3 on 连接条件§ 查询的结果为两个表匹配到的数据加右表特有的数据,对于左表中不存在的数据使用nullo 自关联select * from 表1inner join 表1 on 连接条件§ 连接查询的一种应用,对同一个表连接多次o 子查询§select...(select ...);- 子查询是辅助主查询的,==要么充当条件,要么充当数据源==- 子查询是可以独立存在的语句,是一条完整的select语句
增加数据
更新数据
删除数据
查询数据