大数据库原理张红娟问题详解

实用标准

11.(1)给学生表增加一个属性Nation,数据类型为Varchar(20): ALTER TABLE Student

ADD Nation VARCHAR(20) NULL;

(2)删除Nation: ALTER TABLE Student Drop Column Nation;

(3)向成绩表中插入记录(\: insert into Grade

values('2001110','3',80);

(4)将学号为2001110的学生的成绩改为70分: update Grade set Gmark='70'

where Sno='2001110';

(5)删除学号为'2001110'的学生的成绩记录: delete from Grade

where Sno='2001110';

(6)在学生表的clno属性上创建一个名为'IX_Class'的索引,以班级号的升序排序: create index IX_Class on Student (clno Asc);

(7)删除'IX_Class'索引: drop index Student.IX_Class;

12.(1)找出所有被学生选修了的课程号: select distinct Cno from Grade;

(2)找出01311班女学生的个人信息: select * from Student

where Clno='01311' and Ssex='女';

(3)找出01311班和01312班的学生姓名、姓名、出生年份 select Sname,Ssex,2014-Sage as [year of birth] from Student

where Clno='01311' or Clno='01312';

(4)找出所有姓李的学生的个人信息

select * from Student where Sname like '李%';

文档大全

实用标准

(5)找出学生李勇所在班级的学生人数 select number

from student inner join class on student.clno=class.clno where sname='李勇'

(6)找出课程名为操作系统的平均成绩、最高分、最低分

select AVG(Gmark) 平均成绩,MAX(Gmark) 最高分,MIN(Gmark) 最低分 from Grade where Cno in

(select Cno from Course where Cname='操作系统')

(7)选修了课程的学生人数;

select COUNT(distinct sno) 学生人数 from Grade

(8)选修了操作系统的学生人数; select COUNT(sno) 学生人数 from course inner join grade on course.cno=grade.cno where Cname='操作系统'

(9)找出2000级计算机软件班的成绩为空的学生姓名 select Sname 学生姓名 from

(Student inner join class on student.clno=class.clno) inner join grade on student.sno=grade.sno where Speciality='计算机软件' and inyear='2000' and gmark is null 13.

1)找出和李勇在同一个班级的学生信息 select * from Student where clno in

(select Clno from Student where Sname='李勇')

2)找出所有与学生李勇有相同选修课程的学生信息

select * from Student

文档大全

实用标准

where sno in

(select sno from grade where cno in

(select cno from grade

where sno in (select sno from student where Sname='李勇')));

3)找出年龄介于学生李勇和25岁之间的学生信息 select * from Student where Sage <25 and Sage>

(select Sage from Student where Sname='李勇')

4)找出选修了课程是操作系统的学生学号和姓名

select Sno 学号,Sname 姓名 from Student where sno in

(select sno from Grade where Cno in

(select Cno from Course

where cno in (select cno from course where Cname='操作系统')));

5)找出没有选修1号课程的所有学生姓名

select Sname 姓名 from Student where not exists

(select * from Grade

where Student.Sno=Grade.Sno and Cno='1')

6)找出选修了全部课程的学生姓名

select Sname 姓名 from Student where not exists

(select * from Course where not exists (select * from Grade

where Student.Sno=Grade.Sno and Grade.cno=course.cno)) 14.

1)查询选修了3号课程的学生学号及成绩,并按成绩的降序排列 select Sno 学号,Gmark 成绩 from Grade where Cno='3'

文档大全

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4