oracle创建个课程表
① 从学生课程表中查询分数最高的10条记录(用Oracle数据库写) 十万火急
select * from <你的表名> where rownum <11 order by <分数列名> desc ;
② 一个面试题 oracle:学生表s(sno、sname),课程表c(cno、cname,cteacher)选课表sc(sno、cno、score)
--1
select * from s where s.sno not in(select sno from c,sc where c.cno=sc.cno and c.cteacher='张三')
--2
select (select sname from s where s.sno=main.sno),avg(sc.score)
from s main,sc
where main.sno=sc.sno
and main.sno in(select sno from s s1,sc sc1 where s1.sno=sc1.sno and sc1.score<60 group by s1.sno having count(sno)>=2)
③ Oracle触发器实现表中有时间就插到另一张表中。然后再将此表中数据删除,有大神吗最好有实例说明
得建插入、删除和更新三种触发器。
create trigger tr_in_选课表 on 选课表
FOR INSERT
as
update 课程表 set 选课人数=选课人数+1 where 课程编号=(select 课程编号 from inserted)
go
--删除的,删除时那就要减1
create trigger tr_del_选课表 on 选课表
FOR DELETE
AS
update 课程表 set 选课人数 = 选课人数-1 where 课程编号=(select 课程编号 from deleted)
GO
--更新选课表的时候
create trigger tr_up_选课表 on 选课表
FOR update
as
----如果更新的是课程编号,即本来先的是英语,后来改数学了
if update(课程编号) begin
update 课程表 set 选课人数=选课人数-1 where 课程编号=(select 课程编号 from deleted)
update 课程表 set 选课人数=选课人数+1 where 课程编号=(select 课程编号 from inserted)
---第一行把旧编号的选课人数-1
--第二行把新编号的选课人数+1
end
--- 大体上就是这么一个逻辑,自己再稍微按需完善一下即可。
GO
④ oracle数据查询求助!教师信息表Teacher(TID, TName)课程表Course(CID, CName, TID)
--selectCID,AVG(score)fromGradegroupbyCIDhavingAVG(score)>=85--大于制等于85分的课程ID
selecta.CNAME,a.TIDfromCoursea
innerjoinTeacherbona.TID=b.TID
wherea.CIDin(selectc.(c.score)>=85)andb.TName='张三'
⑤ oracle中创建学生表 课程表 成绩表根据要求创建三个表的结构代码
create table 学生表
(
学生表字段1 varchar2(20)版,
学生表字段权1 varchar2(20),
学生表字段1 varchar2(20),
)
create table 课程表
(
课程表字段1 varchar2(20),
课程表字段2 varchar2(20),
课程表字段3 varchar2(20),
)
create table 成绩表
(
成绩表字段1 varchar2(20),
成绩表字段2 varchar2(20),
成绩表字段3 varchar2(20),
)
⑥ oracle触发器,如果此学生在score表中检测到的某一门课程有分数,则这门课程在选课表中不能退课。
createorreplacetriggertri_
begin
declareiexistsnumber(10);
begin
begin
selectcount(*)intoiexistsfromscorewheresno=:old.snoandcno=:old.cno;
exceptionwhenno_data_foundthen
iexists:=0;
end;
ifiexists>0then
RAISE_APPLICATION_ERROR(-20001,'课源程有分数,这门课程在选课表中不能退课');
endif;
end;
end;
没有测试,应该差不多