update test031
set credit=(select credit from pub.course
where test031.cid=pub.course.cid and score>=60) update test031 set credit=0 where score<60
create table test03 as select sid,sum(credit) sum_credit from test031 group by sid update test4_03
set sum_credit=(select test03.sum_credit from test03
where test03.sid=test4_03.sid)
4、将pub用户下表student_41及数据复制到主用户的表test4_04中,使用alter table语句为表增加五个列:“总成绩:sum_score”、 “平均成绩:avg_score”(四舍五入到个位)、“总学分:sum_credit”、“院系编号:did varchar(2) ”。
根据院系名称到pub.department或者pub.department_41中,找到对应编号,填写到院系编号中,如果都没有对应的院系,则填写为00。
drop table test4_04 drop table test04
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) select *from pub.department
create table test04 as select* from pub.department
insert into test04 select*from pub.department_41 update test4_04
set did=(select test04.did from test04
where test4_04.dname=test04.dname) where dname in(select dname from test04) update test4_04 set did='00'
where dname not in(select dname from test04) or dname is null
update dbtest set test=4 select * from dbscore
5、将pub用户下表student_41及数据复制到主用户的表test4_05中,使用alter table语句为表增加五个列:“总成绩:sum_score”、 “平均成绩:avg_score”(四舍五入到个位)、“总学分:sum_credit”、“院系编号:did varchar(2) ”。
(1) 利用pub.student_course、pub.course,统计 “总成绩”; (2) 利用pub.student_course、pub.course,统计“平均成绩”; (3) 利用pub.student_course、pub.course,统计 “总学分”; (4) 根据院系名称到pub.department或者pub.department_41中,找到
对应编号,填写到院系编号中,如果都没有对应的院系,则填写为00。
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 test4_01.sum_score from test4_01
where test4_01.sid=test4_05.sid) update test4_05
set avg_score=(select test4_02.avg_score from test4_02
where test4_02.sid=test4_05.sid) update test4_05
set sum_credit=(select test4_03.sum_credit from test4_03
where test4_03.sid=test4_05.sid) update test4_05
set did=(select test04.did from test04
where test04.dname=test4_05.dname) where dname in (select dname from test04) update test4_05 set did='00'
where dname not in (select dname
from test04) or dname is null update dbtest set test=4 select * from dbscore
6、将pub用户下的Student_42及数据复制到主用户的表test4_06中,对表中的数据进行整理,修复那些不规范的数据: 剔除姓名列中的所有空格;
select *from pub.student_42 drop table test4_06
create table test4_06 as select* from pub.student_42
update test4_06
set name=replace(name,' ','')
7、将pub用户下的Student_42及数据复制到主用户的表test4_07中,对表中的数据进行整理,修复那些不规范的数据:
对性别列进行规范(需要先确定哪些性别数据不规范,也就是那些和大多数不一样的就是不规范的);
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、将pub用户下的Student_42及数据复制到主用户的表test4_08中,对表中的数据进行整理,修复那些不规范的数据:
对班级列进行规范(需要先确定哪些班级不规范)。
create table test4_08 as select* from pub.student_42 update test4_08
set class=replace(class,'级','') update test4_08
set class=replace(class,' ','')
9、将pub用户下的Student_42及数据复制到主用户的表test4_09中,对表中的数据进行整理,修复那些不规范的数据:
年龄为空值的根据出生日期设置学生年龄(年龄=2012-出生年份),年龄不为空值的不要改变。
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、 将pub用户下的Student_42及数据复制到主用户的表test4_10中,对表
中的数据进行整理,修复那些不规范的数据: (1) 剔除姓名列中的所有空格; (2) 剔除院系名称列中的所有空格;
(3) 对性别列进行规范(需要先确定哪些性别数据不规范,也就是那些
和大多数不一样的就是不规范的);
(4) 对班级列进行规范(需要先确定哪些班级不规范)。
(5) 年龄为空值的根据出生日期设置学生年龄(年龄=2012-出生年份),
年龄不为空值的不要改变。
select *from pub.student_42 drop table test4_06
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=replace(sex,'性','') update test4_10
set sex=replace(sex,' ','')
update test4_10
set age=2012-extract(year from birthday) where age is null
update test4_10
set class=replace(class,'级','') update test4_10
set class=replace(class,' ','')
update dbtest set test=4 select * from dbscore