Oracle创建学生选课数据库。完成下列要求:

Oracle创建学生选课数据库。完成下列要求:,第1张

学生表 student

课程表 course

学生选课关系表 stucourse

create table student(sno number primary key,sname varchar2(20))

insert into student values(1,'alley')

insert into student values(2,'bob')

commit

create table course(cno number primary key,cname varchar2(20))

insert into course values(1,'语文')

insert into course values(2,'数学')

commit

 create table stucourse(sno number,cno number)

alter table stucourse add constraint pk_stucource primary key(sno,cno)

     insert into stucourse values(1,1)

 insert into stucourse values(1,2)

     insert into stucourse values(2,1)

     commit

2. select a.sname,c.cname

from student a,stucourse b,course c

where a.sno = b.sno and b.cno=c.no

3.  查询选修一门以上的学生,按学号从小到大排序

select a.sno, a.sname

  from student a,stucourse b,course c

  where a.sno = b.sno and b.cno=c.no

group by a.sno,a.sname

having count(1)>=1

order by a.sno

4、各用一条语句实现下列功能:添加表的列、更新表的某一字段值、删除表的列、删除表数据、修改表的名称。

alter table student add ssex varchar2(2)

update student set ssex='女'

alter table student drop column ssex

delete from student where sno=1

alter table student rename to studentnew

5、在PL/SQL中执行SELECT语句:在某一实体表中,查询符合某一条件的记录,并显示相应的几个字段值

select  sno, sname

from student

where sno=1

6、用CASE语句实现一多分支结构

select  case when sno=1 then '学号1‘ when sno=2  then '学号2' else '其他学号' end

from student

(1)、select 学号,姓名,年龄 from Student order by 年龄 desc

(2)、select (select 课程名 from Course c where c.课程号=s.课程号) 课程名称, s.分数 from sc s

where s.学号=(select st.学号 from Student where 姓名='张三')

(3)、select 姓名 from Student where 学号 in ( select distinct 学号 from SC where 分数>=60 )

(4)、select Avg(年龄) from Student st where st.学号 in( select sc.学号 from sc sc where sc.课程号 in (select 课程号 from Course c where 课程名='101'))

and 性别='女'

(5)、select (select 姓名 from Student st where st.学号=sc1.学号) 学生姓名,sc1.分数 from SC sc1

where sc1.分数 in (select max(分数) from sc sc where sc.课程号 in (select 课程号 from Course c where c. 任课老师='张青'))

and sc.课程号 in (select 课程号 from Course c where c. 任课老师='张青')

(6)delete from SC s where s.分数<60

(7)update SC set 分数=avg(select 分数 from sc where 课程号='203') where 学号='105' and 课程号='203'

(8)create view over80 as

select sc1.学号,(select 姓名 from Student st where st. 学号=sc1.学号) 姓名,

sc1.课程号,(select 课程名 from Course c where c. 课程号=sc1.课程号) 课程名,(select 任课老师 from Course c where c. 课程号=sc1.课程号) 任课老师,

sc1.分数

from sc sc1 where sc1.分数>80


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9898065.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存