第3次作业-SQL语句的基本使用2

发布时间 2023-09-25 18:46:38作者: Xiiin
1.crate  database studb;
create table stu
    -> (学号 char(4) not null,
    -> 姓名 char(8) not null,
    -> 性别 char(2),
    -> 出生日期 date,
    -> 家族住址 varchar(50),
    -> primary key(学号));

 insert into stu(学号,姓名,性别,出生日期,家庭住址)
    -> values('0001','张青平','男','2000-10-01','衡阳市东风路77号'),
    -> ('0002','刘东阳','男','1998-12-09','东阳市八一北路33号'),
    -> ('0003','马晓夏','女','1995-05-12','长岭市五一路763号'),
    -> ('0004','钱忠理','男','1994-09-23','滨海市洞庭大道279号'),
    -> ('0005','孙海洋','男','1995-04-03','长岛市解放路27号'),
    -> ('0006','郭小斌','男','1997-11-10','南山市红旗路113号'),
    -> ('0007','肖月玲','女','1996-12-07','东方市南京路11号'),
    -> ('0008','张玲珑','女','1997-12-24','滨江市新建路97号');
2.alter table curriculum
    -> drop 课程名称;

3.alter table grade
    -> modify  分数 decimal(5,2);

4.alter table student_info
    -> add 备注 varchar(50);

5.delete from stu
    -> where 学号='0004';

6.update stu
    -> set 家庭住址='滨江市新建路96号'
    -> where 学号='0002';

7.alter table stu
    -> drop 备注;

8.1)select 学号,姓名,出生日期 from student_info;

2.)select 姓名,家庭住址 from student_info
    -> where 学号='0002';

3.)select 姓名,出生日期 from student_info
    -> where 出生日期>1995-01-01 and 性别='女';

9.1)elect 学号,课程编号,分数 from grade
    -> where 分数 between 70 and 80;

2.)select avg(分数) as 平均成绩 from grade
    -> where 课程编号='0002';

3.)select count(*) 选课人数,count(分数) from grade
    -> where 课程编号='0003';

4.)
mysql> select 姓名,出生日期 from student_info
    -> order by 出生日期 desc;

5.)select 学号,姓名 from stu
    -> where 姓名 like '张%';