169-mysql知识点01

10 篇文章 0 订阅



先来复习一下简单的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';





 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值