msyql中单表语句
二、聚合函数
(1)max 最小值
select max(math) from student
(2)min 最大值
select min(math) from student
(3)sum 总数
select sum(math) from student
(4)avg平均数
select avg(math) from student
(5)count 统计个数
select count(math) from student
(6)distinct 去重
select DISTINCT(math) from student
三、grpup by 分组
案例1:分组求出每个班级的平均数
select class,avg(math) from student group by class

having 接group by 后面使用
案例2:分组求出每个班级的平均数小于80分
select class,avg(math) as a from student group by class HAVING a<80;

四、update set 修改
(1)
案例:
UPDATE student set name= " xh" where id=1

五、删除数据
(1)delete 删除表数据
案例:DELETE from student where id=1

(2)truncate快速删除表内容,只剩余表结构
案例:truncate student;

(3)drop table删除整张表
drop table删除整张表
DROP table student ;

删除速度由快到慢:
drop>truncate>deleter
六、快捷方式
ctrl+/ 多行注释
shift+ctrl+/取消注释
单行注释

七、备份
在数据中备份
(1)备份表结构
案例:
create table fuzhi like student ;

(2)备份表数据
a、备份部分数据
INSERT into fuzhi(id,age) select id,age from student;

b、备份全部数据
INSERT into mm select * from student

(3)备份报表结构和数据
create table nn as (select * from student)

在linux中备份:
(1)备份数据
语句:mysqldump -u root -p 数据库名>备份的路径/备份的压缩名.sql
mysqldump -u root -p hh>/home/hz56.sql

八、还原数据
a、新建一个数据库
create datebase 数据库名称

b、还原数据
mysql -u root -p kk</home/hz56.sql

浙公网安备 33010602011771号