1、表说明
成都创新互联主营平利网站建设的网络公司,主营网站建设方案,重庆APP开发公司,平利h5成都微信小程序搭建,平利网站营销推广欢迎平利等地区企业咨询
student(学生表)、teacher(教师表)、course(课程表)、sc(分数表)
2、创建表
create table student(
sno varchar2(10) primary key,
sname varchar2(20),
sage number(2),
ssex varchar2(5)
);
create table teacher(
tno varchar2(10) primary key,
tname varchar2(20)
);
create table course(
cno varchar2(10),
cname varchar2(20),
tno varchar2(20),
constraint pk_course primary key (cno,tno)
);
create table sc(
sno varchar2(10),
cno varchar2(10),
score number(4,2),
constraint pk_sc primary key (sno,cno)
);
3、插入初始化数据
/*******初始化学生表的数据******/
insert into student values ('s001','张三',23,'男');
insert into student values ('s002','李四',23,'男');
insert into student values ('s003','吴鹏',25,'男');
insert into student values ('s004','琴沁',20,'女');
insert into student values ('s005','王丽',20,'女');
insert into student values ('s006','李波',21,'男');
insert into student values ('s007','刘玉',21,'男');
insert into student values ('s008','萧蓉',21,'女');
insert into student values ('s009','陈萧晓',23,'女');
insert into student values ('s010','陈美',22,'女');
commit;
/******************初始化教师表***********************/
insert into teacher values ('t001', '刘阳');
insert into teacher values ('t002', '谌燕');
insert into teacher values ('t003', '胡明星');
commit;
/***************初始化课程表****************************/
insert into course values ('c001','J2SE','t002');
insert into course values ('c002','Java Web','t002');
insert into course values ('c003','SSH','t001');
insert into course values ('c004','Oracle','t001');
insert into course values ('c005','SQL SERVER 2005','t003');
insert into course values ('c006','C#','t003');
insert into course values ('c007','JavaScript','t002');
insert into course values ('c008','DIV+CSS','t001');
insert into course values ('c009','PHP','t003');
insert into course values ('c010','EJB3.0','t002');
commit;
/***************初始化成绩表***********************/
insert into sc values ('s001','c001',78.9);
insert into sc values ('s002','c001',80.9);
insert into sc values ('s003','c001',81.9);
insert into sc values ('s004','c001',60.9);
insert into sc values ('s001','c002',82.9);
insert into sc values ('s002','c002',72.9);
insert into sc values ('s003','c002',81.9);
insert into sc values ('s001','c003','59');
commit;
把成绩列的值加起来就是总成绩,总成绩/成绩列数 就是平均成绩了嘛,但在求成绩列的时候要注意成绩为0的是否去除,可用sign。
比如:score
sno yy yw
123 90 0
145 97 60
select sno,yy,yw,yy+yw,(yy+yw)/(sign(yy)+sign(yw)) from score;
oracle中,有一个学生成绩视图,怎样给这个视图添加一列,并且在这一列中给学生的总成绩排名
你好,view是不可以增加列的,你只能修改view的基表,然后重建view。
如果你的表结构是student_cj(no,name,score1,score2,score3)
原来的view为
create view v_student_cj
as
select no,name,score1,score2,score3 from student_cj;
必须执行以下命令来满足你的需求
create or replace view v_student_cj
as
select no,name,score1,score2,score3,(score1+score2+score3) sum
from student_cj
order by sum desc;