oracle如何创建视图

2025-04-08 21:00:33
推荐回答(2个)
回答1:

1
create view V_StudInfo
as
select a.学号,a.姓名,b.课程号,b.课程名,
case when c.成绩 between 90 and 100 then '优'
when c.成绩 between 80 and 89 then '良'
when c.成绩 between 70 and 79 then '中'
when c.成绩 between 60 and 69 then '及格'
else '不及格' end 成绩等级
from 学生表 a,课程表 b, 成绩表 c where a.学号=c.学号
and b.课程号=c.课程号
 
2
create view V_Stud
as
select a.学号,a.姓名,count(*) 所修科目数,avg(成绩) 平均成绩
from 学生表 a,课程表 b, 成绩表 c where a.学号=c.学号
and b.课程号=c.课程号
and a.学号 in
(select a.学号
from 学生表 a,课程表 b, 成绩表 c where a.学号=c.学号
and b.课程号=c.课程号 and b.课程名='英语' and c.成绩>75)

 

表名和字段名,自己跟你实际的核对一下,不同的改一下

回答2:

badkano的 1 保留
create view V_StudInfo
as
select a.学号,a.姓名,b.课程号,b.课程名,
case when c.成绩 between 90 and 100 then '优'
when c.成绩 between 80 and 89 then '良'
when c.成绩 between 70 and 79 then '中'
when c.成绩 between 60 and 69 then '及格'
else '不及格' end 成绩等级
from 学生表 a,课程表 b, 成绩表 c where a.学号=c.学号
and b.课程号=c.课程号

我改一下 badkano 2的写法,没有group分组,下面的应该执行不了。

create view V_Stud
as
select a.学号,a.姓名,count(*) 所修科目数,avg(成绩) 平均成绩
from 学生表 a,课程表 b, 成绩表 c where a.学号=c.学号
and b.课程号=c.课程号
and a.学号 in
(select a.学号
from 学生表 a,课程表 b, 成绩表 c where a.学号=c.学号
and b.课程号=c.课程号 and b.课程名='英语' and c.成绩>75)

------------------------------------------------------------------------------------
修改如下
2
create view V_Stud
as
select a.学号,max(a.姓名) 姓名,count(*) 所修科目数,avg(成绩) 平均成绩
from 学生表 a,课程表 b, 成绩表 c
where a.学号=c.学号
and b.课程号=c.课程号
group by d a.学号
having a.学号 in
(select a.学号
from 学生表 a,课程表 b, 成绩表 c
where a.学号=c.学号
and b.课程号=c.课程号 and b.课程名='英语' and c.成绩>75)