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)

转载于:https://my.oschina.net/yanjianhai/blog/133400

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值