mysql插入数据
insert into 表名(名称1,-,-)values(插入的数据);
mysql读取数据
select * from 数据表名
或select 表中字段名 from 表名
更新数据
update 表名 set 名称=新数据;
删除数据
delete from 表名 where 名称=数据;
like 子句
select 表中字段名 from where 表中字段名 like 数据;
like 相当于 =
可用and或者or指定一个或多个
可在delete或update命令中使用where like 子句来指定条件 一定要和where连用eg`update from 表名 set 表中字段名=新数据 where 表中字段名 like 旧数据; `
union操作符
用于连接两个以上的select语句的结果组合集合中。多个select语句会删除重复的数据。
eg:`select 表中字段名1 from 表名1 union select 表中字段名2 from 表名2`
可以用多个union连接
MySQL排序
order by asc(升序) desc(降序)默认升序
select * from 表名 order by 表中字段名 asc;
MySQL分组
group by 语句
eg:select 表中字段名 ,count(*)from表名 group by 表中字段名
***count(*)不能分开,逗号不能漏,count为函数,我们还可以使用sum,avg等函数。
MySQL 使用with rollup
实现分组求和
`select 表中字段名,sum表中字段名as任意你想要的名称 from 表名 group by 表中字段名 with rollup;`
null记录总数,可用`select coalesce (表中字段名,'任意你想要的名称'),sum(表中字段名)as 任意你想要的名称 同上;`
同样不要漏逗号了;