实验三 SQL 复杂查询
目的:
掌握复杂数据查询操作。
内容:
掌握各种连接查询、嵌套查询的使用
步骤:
1)实验一中的数据为基础
2) 对各表中的数据进行不同条件的连接查询和嵌套查询;
查询每个学生及其选课情况;
查询每门课的间接先修课
将STUDENT,SC进行右连接
查询既选修了2号课程又选修了3号课程的学生姓名、学号;
查询和刘晨同一年龄的学生
选修了课程名为“数据库”的学生姓名和年龄
查询其他系比IS系任一学生年龄小的学生名单
查询其他系中比IS系所有学生年龄都小的学生名单
查询选修了全部课程的学生姓名
查询计算机系学生及其性别是男的学生
查询选修课程1的学生集合和选修2号课程学生集合的差集
查询李丽同学不学的课程的课程号
查询选修了3号课程的学生平均年龄
求每门课程学生的平均成绩
统计每门课程的学生选修人数(超过3人的才统计)。要求输出课程号和选修人数,结果按人数降序排列,若人数相同,按课程号升序排列
查询学号比刘晨大,而年龄比他小的学生姓名。
求年龄大于所有女同学年龄的男同学姓名和年龄
附录:
语句清单
--sql 查询实验三代码
--------1
select student.*,o, ----左外连接(显性连接)
from student left join sc on =
/*
select student.*,o,
from student inner join sc ----内连接法(显性连接)
on =
*/
/*
select student.*,o, ----------隐性连接
from student,sc
where =
*/
select ame,,o
from course first,course second ----------2
where =o
select student.*,sc.* ---------------3
from student right join sc on =
select ,sname
from student,sc,(select
from student,sc -----4 导出表的使用
where = o='2'
group by )as result(sno)
where = o='3'
group by ,
select ,sname
from student,sc as x --------4法二
where = o='2' and exists(select
from student,sc as y
o='3' and exists(select *
f
sql 数据库上机实验三 来自淘豆网m.daumloan.com转载请标明出处.