视图实现 连接查询与嵌套查询

凉夜微暖 分享 2020-06-22 下载文档

------------------(连接查询)--------------------

1)查询信息系且年龄在21 岁以下(含21 岁)的女生姓名及其年龄。

select sname,age from student,dept

where student.deptno=dept.deptno and dept.dname='信息' and age<=21 and sex='女'

方法2: 用视图实现查询:注意表之间的连接条件、筛选条件的设置 查询结果

2)查询计算机科学与技术系教师的授课情况(显示系名、教师名、课程名)。

select dname,tname,cname from dept,course,teacher

where course.tno=teacher.tno and teacher.deptno=dept.deptno

视图实现:

1

3)查询每个学生的选课情况(显示学号、姓名、系名、课程名、成绩)。

select student.sno,sname,dname,cname,grade from student,dept,course,sc

where student.deptno=dept.deptno and sc.sno=student.sno and sc.cno=course.cno

视图实现:

2

4)查询各个系的学生人数(显示系名、学生人数)。

select dname,count(sno) 学生人数--count(sex)---count(age) from dept,student

where student.deptno=dept.deptno group by dname

视图实现:注意设置分组依据

5)查询每个学生的总分和平均分(显示学号、姓名、总分、平均分)。 select student.sno,sname,sum(grade) 总分,avg(grade) 平均分 from student,sc

where student.sno=sc.sno group by student.sno,sname

视图实现:注意设置分组依据

3

6)查询平均分在以上的学生(显示学号、姓名、平均分)。 select student.sno,sname,avg(grade) 平均分 from student,sc

where student.sno=sc.sno group by student.sno,sname having avg(grade)>85

视图实现:注意设置分组依据,分组后筛选

4

7)查询刘田老师所在的系(显示教师号、教师名、系名)。 select tno,tname,dname from teacher,dept

where teacher.deptno=dept.deptno and tname='刘田'

------------------------嵌套查询-------------------------- 1)查询修课总学分在10 学分以下的学生姓名。

select sname from student where sno in( select sno

from sc,course

where sc.cno=course.cno group by sno

having sum(credit)<10 )

--方法2:视图实现

--先创建一个视图\总学分在10以下的学号\,用于保存总学分在10以下的学号数据。

5


视图实现 连接查询与嵌套查询 .doc 将本文的Word文档下载到电脑

下一篇:营业税改征增值税

相关推荐
相关阅读
本类排行
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 7

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xxxxxx QQ:xxxxxx