山东大学数据库系统实验答案

1.create table test4_01 as
(
select * 
from pub.STUDENT_41)
alter table test4_01 add sum_score
create table test41 as 
(select sum(score) sumscore,sid
from pub.STUDENT_COURSE
group by sid)
update test4_01
set sum_score=(
select sumscore
from test41
where test41.sid=test4_01.sid)
2.create table test4_02
as(select * 
from pub.STUDENT_41)
create table test42 as
(select sid,avg(score) avgscore
from pub.STUDENT_COURSE
group by sid)
alter table test4_02 add avg_score numeric(4,1)
update test4_02
set avg_score=(
select avgscore
from test42
where test42.sid=test4_02.sid)
3.create table test4_03 as
(select *
from pub.STUDENT_41)
alter table test4_03 add sum_credit int
create table test43 as
(select sum(credit) sumcredit,sid
from pub.STUDENT_COURSE natural join pub.COURSE 
where pub.STUDENT_COURSE.SCORE>=60
and pub.STUDENT_COURSE.SCORE is not null
group by sid)
update test4_03
set sum_credit=(
select sumcredit 
from test43
where test43.sid=test4_03.sid)
4.create table test4_04 as
(select *
from pub.STUDENT_41)
update test4_04
set dname=(
select did
from pub.DEPARTMENT
where pub.DEPARTMENT.DNAME=test4_04.dname)
update test4_04 
set dname=
(select dname
from pub.STUDENT_41
where test4_04.sid=pub.student_41.sid
)where dname is null
5.
create table test4_05 as
(select *
from pub.STUDENT_41)
alter table test4_05 add sum_score int
alter table test4_05 add avg_score numeric(4,1)
alter table test4_05 add sum_credit int
alter table test4_05 add did varchar(2)
update test4_05
set sum_score=(
select sum_score
from test4_01
where test4_01.sid=test4_05.sid)
update test4_05
set avg_score=(
select avg_score
from test4_02
where test4_02.sid=test4_05.sid)
update test4_05
set sum_credit=(
select sum_credit 
from test4_03
where test4_03.sid=test4_05.sid)
update test4_05
set did=(
select did
from pub.DEPARTMENT
where pub.DEPARTMENT.DNAME=test4_05.dname)
where dname in(select dname from pub.DEPARTMENT)
update test4_05
set did=(
select did
from pub.DEPARTMENT_41
where pub.DEPARTMENT_41.DNAME=test4_05.dname)
where dname in(select dname from pub.DEPARTMENT_41)
update test4_05
set did='00'
where did is null
6.create table test4_06 as
(select * 
from pub.STUDENT_42)
update test4_06
set name=replace(name,' ','')
7.create table test4_07 as
(select *
from pub.STUDENT_42)
update test4_07
set sex=replace(sex,' ','')
update test4_07
set sex=replace(sex,'性','')
8.create table test4_08 as
(select * 
from pub.STUDENT_42)
update test4_08
set class=replace(class,'级','')
9.
create table test4_09 as
(select *
from pub.STUDENT_42)
update test4_09
set age=(2012-extract(year from birthday))
where age is null
10.create table test4_10 as
(select *
from pub.STUDENT_42)
update test4_10
set name=replace(name,' ','')
update test4_10
set sex=replace(sex,' ','')
update test4_10
set sex=replace(sex,'性','')
update test4_10
set class=replace(class,'级','')
update test4_10
set age=(2012-extract(year from birthday))
where age is null
update test4_10
set dname=replace(dname,' ','')

你可能感兴趣的:(数据库学习)