数据库实验七

1.create table test7_01 
(First_name varchar(4),
frequency numeric(4))
create table test71 as
(select substr(name,2,2) as first_name
from pub.STUDENT)
create table test72 as
(select first_name,count(first_name)
from test71
group by first_name)
insert into test7_01(first_name,frequency)
(select *
from test72)
2.create table test7_02
(letter varchar(2),
frequency numeric(4)
)
create table test721 as(
select substr(name,2,1) as letter
from pub.STUDENT)
create table test722 as(
select letter,count(letter) as frequency
from test721
group by letter)
create table test723 as(
select substr(name,3,1)as letter
from pub.STUDENT
where substr(name,3,1) is not null
)
create table test724 as(
select letter,count(letter) as frequency
from test723
group by letter
)
insert into test7_02
((select * from test722)
union all(select * from test724))//不知道为什么这一种算法不正确
create table test721 as(
(select substr(name,2,1) as letter from pub.STUDENT) union all
(select substr(name,3,1) as letter from pub.STUDENT
where substr(name,3,1) is not null))
create table test722 as(
select letter,count(letter) as frequency
from test721
group by letter)
insert into test7_02(letter,frequency)(
select *
from test722)
3.create table test7_03
(dname varchar(30),
class varchar(10),
P_count1 int,
p_count2 int,
p_count int)
create table test731 as(
select dname,class,count(sid)as p_count
from pub.STUDENT
where dname is not null
group by dname,class)
create table test732 as(
select pub.STUDENT.sid,sum(credit) as scredit
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 score>=60
group by pub.STUDENT.sid)
create table test733 as
(select dname,class,count(pub.STUDENT.sid) as p_count1
from test732,pub.STUDENT
where pub.STUDENT.SID=test732.sid
and scredit>=10 and dname is not null
group by dname,class)
create table test734 as
(select dname,class,count(pub.STUDENT.sid) as p_count2
from test732,pub.STUDENT
where pub.STUDENT.SID=test732.sid
and scredit<10 or scredit is null and dname is not null
group by dname,class
insert into test7_03(dname,class,p_count)(
select*
from test731)
update test7_03 set p_count1=(select p_count1
from test733
where test733.DNAME=test7_03.dname
and test733.class=test7_03.class)
update test7_03 set p_count2=(select p_count2
from test734
where test734.DNAME=test7_03.dname
and test734.class=test7_03.class)//这种算法也不正确
3.create table test7_03
(dname varchar(30),
class varchar(10),
P_count1 int,
p_count2 int,
p_count int)
create table test731 as(select sid,sum(credit) as scredit
from pub.COURSE,pub.STUDENT_COURSE
where pub.STUDENT_COURSE.CID=pub.course.cid
and score>=60
group by sid)
create table test732 as
(select *
from pub.STUDENT natural left join test731
)
create table test733 as
(select dname,class,count(sid) as p_count
from test732
group by dname,class)
create table test734 as
(select dname,class,count(sid) as p_count1
from test732
where scredit>=10
group by dname,class)
create table test735 as
(select dname,class,count(sid) as p_count2
from test732
where scredit<10 or scredit is null
group by dname,class)
insert into test7_03
(select *
from test734 natural left join test735 natural join test733)
update test7_03 set p_count1=0 where p_count1 is null;//错误的算法,差一行数据,没找到错误原因
3.create table test7311 as
(select dname,class,count(sid) as p_count 
from pub.STUDENT
where dname is not null
group by dname,class)
create table test7322 as(
select pub.STUDENT.sid,sum(credit) as scredit
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 score>=60
group by pub.STUDENT.sid)
create table test7333 as
(select dname,class,count(pub.STUDENT.sid) as p_count1
from test7322,pub.STUDENT
where pub.STUDENT.SID=test7322.sid
and scredit>=10 and dname is not null
group by dname,class)
create table test7313 as
(select *
from test7311 natural left outer join test7333)
update test7313 set p_count1=0 where p_count1 is null
create table test7_03 as
(select dname,class,p_count1,p_count-p_count1 as p_count2,p_count
from test7313)
4.create table test7_04
(dname varchar(30),
class varchar(10),
p_count1 int,
p_count2 int,
p_count int)
create table test741 as(
select dname,class,count(sid)as p_count
from pub.STUDENT
group by dname,class)
create table test742 as
(select sid,sum(credit) as scredit
from pub.COURSE,pub.STUDENT_COURSE
where pub.COURSE.CID=pub.student_course.cid
and score>=60
group by sid)
create table test743 as(
select dname,class,count(pub.STUDENT.sid) as p_count1
from pub.STUDENT,test742
where pub.STUDENT.SID=test742.sid
and scredit>=10
and pub.STUDENT.class>2008
and pub.STUDENT.dname is not null
group by dname,class)
insert into test743(
select pub.student.DNAME,pub.STUDENT.CLASS,count(pub.STUDENT.SID)
from pub.STUDENT,test742
where pub.STUDENT.SID=test742.sid
and scredit>=8
and class<=2008
and dname is not null
group by dname,class)
create table test7_04 as(
select dname,class,p_count1,p_count-p_count1 as p_count2,p_count
from test743 natural left join test741)

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值