王永志的博客

舒心、快乐,比什么都重要

第3次作业-SQL语句的基本使用2(修改表-基本查询)

第3次作业-SQL语句的基本使用2(修改表-基本查询)

  1. 使用SQL语句ALTER TABLE修改curriculum表的“课程名称”列,使之为空。
 alter table curriculum
 -> drop 课程名称;

2.使用SQL语句ALTER TABLE修改grade表的“分数”列,使其数据类型为decimal(5,2)。
mysql> alter table grade
    -> modify 分数 decimal(5,2);

3.使用SQL语句ALTER TABLE为student_info表添加一个名为“备注”的数据列,其数据类型为varchar(50)。

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

4.使用SQL语句创建数据库studb,并在此数据库下创建表stu,表结构与数据与studentsdb的student_info表相同。
mysql> create table stu
    -> (学号 char(4) not null,
    -> 姓名 char(8) not null,
    -> 性别 char(2) null,
    -> 出生日期 date null,
    -> 家族住址 varchar(50) null,
    -> primary key(学号));

5.使用SQL语句删除表stu中学号为0004的记录。
mysql> delete from stu
    -> where 学号 ='0004';

6.使用SQL语句更新表stud中学号为0002的家庭住址为“滨江市新建路96号”。
mysql> update stu
    -> set 学号= '0002'
    -> where 家族住址 ='滨江市新建路96号';
mysql> update stu
    -> set 家族住址 ='滨江市新建路96号'
    -> where 学号='0002';

7.删除表stud的“备注”列
mysql> alter table stu![](https://img2023.cnblogs.com/blog/3276465/202309/3276465-20230925184949302-1373530378.png)

    -> drop 备注;

8.在studentsdb数据库中使用SELECT语句进行基本查询

(1)在student_info表中,查询每个学生的学号、姓名、出生日期信息。
mysql> select 学号,姓名,家庭住址 from student_info;

(2)查询student_info表学号为 0002的学生的姓名和家庭住址。
mysql> select 姓名,家庭住址 from student_info where 学号='0002';

(3)查询student_info表所有出生日期在95年以后的女同学的姓名和出生日期。
mysql> select 姓名,出生日期 from student_info
    -> where 出生日期>'1995-01-01'and (性别='女');

9.使用select语句进行条件查询。
(1)在grade表中查询分数在70-80范围内的学生的学号、课程编号和成绩。
mysql> select 学号,课程编号,分数 from grade
      where 分数 between 70 and 80;

(2)在grade表中查询课程编号为0002的学生的平均成绩。
mysql> select round(avg(分数),1) 平均分数 from grade where 课程编号='2';

(3)在grade表中查询选修课程编号为0003的人数和该课程有成绩的人数。
select count(*) 选课人数,count(分数) 有分数人数 from grade  
    where 课程编号 = '3';

(4)查询student_info的姓名和出生日期,查询结果按出生日期从大到小排序。
 select 姓名,出生日期 from student_info order by 出生日期 desc;  

(5)查询所有姓名“张”的学生的学号和姓名。
select 学号,姓名 from student_info where 姓名 like '张%';

posted @ 2023-10-02 13:55  True范特西  阅读(279)  评论(0)    收藏  举报