------------------(连接查询)--------------------
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
搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新幼儿教育视图实现 连接查询与嵌套查询 全文阅读和word下载服务。
相关推荐: