几个小问题,高手五分钟。最迟明晚给分结帖!不够分再给!

liuq 2006-06-20 07:22:50
本人不做数据库方面开发,但要做个题,请高手指导。
学生表结构:学号(主键)姓名
成绩表结构:学好(主键1)课程号(主键2)成绩
(1)求所有同学所有课程的总分。
(2)写一个针对每个同学计算所有科目平均成绩的存储过程。
(3)构造触发器完成以下功能:当增加一个新同学时,自动在Score表中增加一个学号;当删除某个学生档案时,相应的该学生的成绩记录全部删除。
(4)写一个完整的游标程序,用来提取李斯各门课程的成绩。(SQL语法)

另外有一个表包含书名和作者
内容:
书名 作者
book1 author1
book1 author2


写个SQL得到结果
book1 author1,author2
多谢。时间紧迫。给个结果,要分另外开帖给。系统一次只允许给100。
...全文
165 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
龙翔飞雪 2006-06-21
  • 打赏
  • 举报
回复
天那~
貌似是 大学数据库理论 的考试题目~ 不是公司面试题
fjmingyang 2006-06-20
  • 打赏
  • 举报
回复
SQL> create table student(xh number primary key,xm varchar2(20));

表已创建。

SQL> create table subject(xkh number primary key,xk varchar2(20));

表已创建。

SQL> create table score(xh number ,xkh number,cj number);

表已创建。

SQL> alter table score add constraint pk_score primary key(xh,xkh);

表已更改。

SQL> insert into student values(1,'zhangsan');

已创建 1 行。

SQL> insert into student values(2,'lisi');

已创建 1 行。

SQL> insert into subject values(1,'math');

已创建 1 行。

SQL> insert into subject values(2,'chinese');

已创建 1 行。

SQL> insert into score values(1,1,80);

已创建 1 行。

SQL> insert into score values(1,2,90);

已创建 1 行。

SQL> insert into score values(2,1,91);

已创建 1 行。

SQL> insert into score values(2,2,83);

已创建 1 行。

SQL> commit;

提交完成。

SQL> select *from student;

XH XM
---------- --------------------
1 zhangsan
2 lisi

SQL> select *from subject;

XKH XK
---------- --------------------
1 math
2 chinese

SQL> select *from score;

XH XKH CJ
---------- ---------- ----------
1 1 80
1 2 90
2 1 91
2 2 83

SQL> select * from student join (select xh,sum(cj) from score group by xh) using(xh);

XH XM SUM(CJ)
---------- -------------------- ----------
1 zhangsan 170
2 lisi 174


(2)
create or replace procedure averageScore(xh number) as
avgScore number;
begin
select avg(cj) into avgScore from score where xh=1;
dbms_output.put_line(avgScore);
end;

(3)
create or replace trigger triStudent
before insert or delete on student for each row
declare
cursor c_subject is select xkh from subject;
begin
--原文:"当增加一个新同学时,自动在Score表中增加一个学号",不是很理解那样做的目的,这里设置新同学所有学科成绩为空
if inserting then
for r_subject in c_subject loop
execute immediate 'insert into score values('||:new.xh||','||r_subject.xkh||',null)';
end loop;
end if;

if deleting then
delete score where xh=:old.xh;
end if ;
end;

(4)
declare
cursor c_score is select s.xk,t.cj from subject s,(select * from score where xh=(select xh from student where xm='lisi')) t where s.xkh=t.xkh ;
begin
for r_score in c_score loop
dbms_output.put_line(r_score.xk||':'||r_score.cj);
end loop;
end;
-------------------------------
math:91
chinese:83


17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧