文档库 最新最全的文档下载
当前位置:文档库 › 数据库上机作业

数据库上机作业

create table student1
(sno char(10),
sname char(10),
ssex char(2),
sage int,
scname char(15),
primary key(sno)
)
1.为教师表增加工资字段,浮点型(salary,默认值2000)。
/* alter table teacher
add salary real default 2000*/
2.将选课表的成绩字段改为实型,最大长度6位,小数位为2位。
/* select * from sc
alter table sc
alter column grade numeric(6,2)*/
3.将学分统一降低1分。
/* select * from couse
update couse
set ccre=ccre-1*/
4.为每个班级增加5名同学。
/* select *from class
update class
set clnum=clnum+5*/
5.把教师“张三”的地址改为18区。
/* select * from teacher
update teacher
set tadd='18区'
where tname='张三'*/
6.把数据结构课成绩降低一半。
(1):/*select * from sc
update sc
set grade=grade/2
where cno in (select cno from couse where cname='数据结构')
*/
(2):/* select * from sc
update sc
set grade=grade*0.5
where cno='g002'*/
7.在系表中插入一条记录(ma,数信,355,9区)。
/* select * from dept
insert into dept
values('ma','数信','355','9区')*/
8.将系表中的“数信”系删除。
/* select * from dept
delete from dept
where dname= 'ma'*/
9.建立一个新表,存放成绩在86分以上的学生的学号,课程号和成绩。
/*create table abc(Sno char(10),Cno char(10), grade int)
insert into abc(Sno,Cno,grade)
(select Sno,Cno,grade
from SC
where grade>=86)*/

1 查询研究所的所有信息,按所人数降序。
2 查询程序语言课的课程号,课程名,学分。
3 查询住在10区的男教师的编号,电话。
4 查询被学生选了课的课程号,按升序排列,去掉重复值。
5 按查询系名称“开头是电子”,电话号码最后为‘6’的所有信息。
6 查询班级人数在29-31只间班级所有信息,将列班级名称改为name,电话号码改为tel。
7 查询网络研所和软件研究所的所有信息(2种方法)。
8 查询T001教师所代课程学分小于6分的课程号,课程名。
9 建立新表class1,插入计算机系的所有班级信息。
10把张三老师所代的课程的学分增加2分。

答案:
/*1 select * from inst
order by inum desc */
/*2 select cno,cname,ccre
from couse
where cname='程序语言'*/
/*3 select tno,ttel
from teacher
where tadd='10区'*/
/*4 select distinct cno
from sc
order by cno*/
/*5 select * from dept
where dname like'电子%' and dtel like'%6'*/
/*6 select clname name,cltel tel
from class
where clnum>29 and clnum<31*/
/*7 select * from inst
where iname='网络' or iname='软件'*/
/*select * from inst
where iname in('网络','软件')*/
/*8 select cno,cname
from couse
where tno='T001' and ccre<6*/
/*9 create table class1(clname char(8),clnum char(10),cltel char(10),dno char(10))
insert into class1(clname,clnum,cltel,dno)
(select clname,clnum,cltel,class.dno from class,dept
where class.dno=dept

.dno and dname='计算机')*/
/*10 update couse
set ccre=ccre+2
where tno in (select tno from teacher where tname='张三')*/

1.课程号为E001的课程的总分和平均分。
2.依班级表,查末位是s的系号及班级数。
3.选课在两门以上且各门课程均及格的学生的学号及其总成绩。
4.学生人数大于2人的班级的具体学生人数。
5.有选课成绩但学分不到6分的学生的学号及学分总数。
6.建表co,插入课程学分平均分在5分以上的系的系号和平均分。
答案:
/*1 select sum(grade),avg(grade)
from sc
where cno='e001'*/
/*2 select dno,count(*)
from class
where dno like'%s'
group by dno */
/*3 select sno,sum(grade)
from sc
where grade>=60
group by sno
having count(sno)>2 */
/*4 select clname,clnum
from class
where clnum>2*/
/*5 select sno,sum(ccre)
from sc,couse
where https://www.wendangku.net/doc/2b13466844.html,o=https://www.wendangku.net/doc/2b13466844.html,o and grade>=0 or ccre<6
group by sno*/
/*6 create table co(cno char(10),avge int)
insert into co(dno,avge)
(select dno,avg(ccre)
from couse
group by dno
having avg(ccre>=5))*/

1.查询选修了e001课且成绩在80分以上的学生姓名。
2.查询每个学生的姓名,选修了的课程名及其成绩。
3.查询"张三"老师讲授的课程名称。
4.查询与“李楷”年龄相同的学生姓名。
5.查询计算机系学生选的课程号及各课的学生选课人数。
6.电子工程系年龄大于17岁且选修了E001课的学生姓名。
7.查询各门成绩在60分以上的同学的姓名及平均成绩。
答案:
/*1 select sname
from sc,student
where sc.sno=student.sno and cno='e001' and grade>80 */
/*2 select sname,cname,grade
from student,couse,sc
where sc.sno=student.sno and https://www.wendangku.net/doc/2b13466844.html,o=https://www.wendangku.net/doc/2b13466844.html,o*/
/*3 select cname
from couse,teacher
where couse.tno=teacher.tno and tname='张三'*/
/*4 select s1.sname
from student s1,student s2
where s1.sage=s2.sage and s1.sname='李楷' and s1.sno<>s2.sno*/
/*5 select https://www.wendangku.net/doc/2b13466844.html,o,count(*)
from sc,dept,class,student
where sc.sno=https://www.wendangku.net/doc/2b13466844.html,o and student.clname=class.clname and class.dno=dept.dno dname='计算机'
/*6 select sname
from sc,student,dept,class
where dept.dno=class.dno and sc.sno=student.sno and
class.clname=student.clname and dname='电子工程' and sage>17 and cno='e001'*/
/*7 select sname,avg(grade) from sc,student
where grade>60 and sc.sno=student.sno
group by sname */


相关文档
相关文档 最新文档