先来复习一下简单的mysql命令
1.
mysql -uroot -p123
2.
show databases;
3.
use abc;
4.
show tables;
5.
create table tb_student(
id int primary key auto_increment,
name varchar(50)
);
6.
select * from tb_student;
7.
insert into tb_student values(0,'abc01');
8.查看每一列的属性和数据类型
describe tb_student;
9.id是自增的,所以插入的时候可以不加上id
insert into tb_student(name) values('abc03');
10.可以连续加入多条数据
insert into tb_student(name) values('abc05'),('abc06');
11.我们查看一下表
show tables;
12.删除一个没用的表
drop table tb_abc;
13.连续删除多个表
drop table tb_test01,tb_test02,tb_test03;
14.再创建一个表
create table tb_score(
id int primary key auto_increment
);
15.新增一条记录
insert into tb_score values(0);
16.删除所有的记录
delete from tb_score;
17.删除id为1的记录
delete from tb_score where id=1;
18.看看这张表的结构
describe tb_score;
19.给这张表增加一个name字段
alter table tb_score add name varchar(50);
20.增加一条数据
insert into tb_score(name) values('abc01');
21.删除掉这个name字段
alter table tb_score drop name;
22.增加一个sid字段
alter table tb_score add sid int;
23.增加一个subject字段
alter table tb_score add subject varchar(50);
24.增加一个score字段
alter table tb_score add score int;
1.新增1条数据
insert into tb_score values(0,1,'math',10);
2.筛选出没有score的学生
select * from tb_student
left join tb_score on
tb_student.id=tb_score.sid
where tb_score.score is null;
3.计算出一共有几个学生
select count(*) from tb_student;
4.求出所有学生的数学成绩平均分
select avg(score) from tb_score where subject='math';