山大数据库实验四:复制表、修改表结构、修改数据

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1.
create table test4_01 as select * from pub.student_41
alter table test4_01 add sum_score int
alter table test4_01 add avg_score numeric (5,1)
alter table test4_01 add sum_credit int
alter table test4_01 add did varchar(2)
update test4_01 set sum_score = (select sum(score) from pub.student_course where test4_01.sid = pub.student_course.sid group by sid)

2.
create table test4_02 as select * from pub.student_41
alter table test4_02 add sum_score int
alter table test4_02 add avg_score numeric (5,1)
alter table test4_02 add sum_credit int
alter table test4_02 add did varchar(2)
update test4_02 set avg_score = (select avg(score) from pub.student_course where test4_02.sid = pub.student_course.sid group by sid)

3.
create table test4_03 as select * from pub.student_41
alter table test4_03 add sum_score int
alter table test4_03 add avg_score numeric (5,1)
alter table test4_03 add sum_credit int
alter table test4_03 add did varchar(2)
create table a as select sid,sum(credit) sum_credit from pub.student_course,pub.course where pub.course.cid=pub.student_course.cid and pub.student_course.score>=60 group by sid
update test4_03 set sum_credit = (select sum_credit from a where test4_03.sid=a.sid)
drop table a

4.
create table test4_04 as select * from pub.student_41
alter table test4_04 add sum_score int
alter table test4_04 add avg_score numeric (5,1)
alter table test4_04 add sum_credit int
alter table test4_04 add did varchar(2)
create table a as select * from pub.department union select * from pub.department_41
update test4_04 set did=(select did from a where a.dname=test4_04.dname)
update test4_04 set did='00' where test4_04.did is null
drop table a

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 (5,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 pub.student_course where test4_05.sid = pub.student_course.sid group by sid)
update test4_05 set avg_score = (select avg(score) from pub.student_course where test4_05.sid = pub.student_course.sid group by sid)
create table a as select sid,sum(credit) sum_credit from pub.student_course,pub.course where pub.course.cid=pub.student_course.cid and pub.student_course.score>=60 group by sid
update test4_05 set sum_credit = (select sum_credit from a where test4_05.sid=a.sid)
drop table a
create table a as select * from pub.department union select * from pub.department_41
update test4_05 set did=(select did from a where a.dname=test4_05.dname)
update test4_05 set did='00' where test4_05.did is null
drop table a

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=substr(sex,1,1) where sex like '_性'
update test4_07 set sex=repl

ace(sex,' ','')

8.
create table test4_08 as select * from pub.student_42
update test4_08 set class=substr(class,1,4)

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 dname = replace(dname,' ','')
update test4_10 set sex=substr(sex,1,1) where sex like '_性'
update test4_10 set sex=replace(sex,' ','')
update test4_10 set class=substr(class,1,4)
update test4_10 set age = 2012-extract(year from birthday) where age is null

相关文档
最新文档