SQL 常用操作2

create table test8_04(sid varchar(12),name varchar(10),dname varchar(30),ds_score int,os_score int)

insert into test8_04 select pub.student.sid,pub.student.name,dname,null,null from pub.student where dname='计算机科学与技术学院' 

update test8_04 set ds_score=(select score from pub.student_course where cid=(select cid from pub.course where name='数据结构') and 
test8_04.sid=pub.student_course.sid) 

update test8_04 set os_score=(select score from pub.student_course where cid=(select cid from pub.course where name='操作系统') and 
test8_04.sid=pub.student_course.sid) 
create table test8_01 as select a.dname,Avg_ds_score,Avg_os_score from 
(select dname,round(avg(score)) as Avg_ds_score from pub.student,pub.student_course,pub.course where pub.student.sid=pub.student_course.sid and pub.student_course.cid=pub.course.cid and pub.course.name='数据结构' and dname is not null group by dname) a,(select dname,round(avg(score)) as Avg_os_score from pub.student,pub.student_course,pub.course where pub.student.sid=pub.student_course.sid and pub.student_course.cid=pub.course.cid and pub.course.name='操作系统' and dname is not null group by dname)b where a.dname=b.dname;
select * from test8_03
update dbtest set test=8
select * from dbscore
create table q as select e.sid,e.name,e.dname,ds_score,os_score from (select a.sid,a.name,dname,score as ds_score from pub.student a,pub.student_course b,pub.course c where a.sid=b.sid and b.cid=c.cid
and dname='计算机科学与技术学院' and c.name='数据结构') e, (select a.sid,a.name,dname,score as os_score from pub.student a,pub.student_course b,pub.course c where a.sid=b.sid and b.cid=c.cid
and dname='计算机科学与技术学院' and c.name='操作系统') f where e.sid=f.sid and e.name=f.name
create table i as select a.sid,a.name,dname,score as ds_score from pub.student a,pub.student_course b,pub.course c where a.sid=b.sid and b.cid=c.cid
and dname='计算机科学与技术学院' and c.name='数据结构'
drop table q
alter table w add ds_score int
delete from w where (sid,name)in(select sid,name from test8_02)
select * from where 
create table u as select a.sid,a.name,dname,score as os_score from pub.student a,pub.student_course b,pub.course c where a.sid=b.sid and b.cid=c.cid
and dname='计算机科学与技术学院' and c.name='操作系统'
select * from test8_02
drop table test8_03
create table test8_03 as select * from (i natural full outer join u)
create table  p as select a.sid,a.name,dname from pub.student a,pub.student_course b,pub.course c where a.sid=b.sid and b.cid=c.cid
and dname='计算机科学与技术学院' 
drop table p
create table test8_04 as select * from (p natural full outer join test8_03)

你可能感兴趣的:(oracle,sql,查询)