当前位置:文档之家› 补充SQL练习(参考答案)

补充SQL练习(参考答案)

Tianqing Zhang SCU 6
查询选了其所在系开始所有课程的学生姓名。 select name from student s where not exists ((select course_no from course where dept=s.dept) except (select course_no from c_s where s.id=c_s.student_id));
3
查询选了“数据库原理”课程的所有学生的学号和姓名。 select id, from student s, c_s, course c where s.id=c_s.student_id and c_s.course_no=c.course_no and ='数据库原理';
Tianqing Zhang SCU 5
查询选课门数最多的学生姓名及其选课门数。 select , count(*) from student s, c_s, course c where s.id=c_s.student_id and c_s.course_no=c.course_no group by s.id, having count(*)>= all (select count(*) from student s, c_s, course c where s.id=c_s.student_id and c_s.course_no=c.course_no group by s.id);
• 创建上述关系及部分数据的的SQL语句见文件 createdb.sql • 请完成以下查询:
– – – – – 查询所有没有被选过的课程。 查询选了“数据库原理”课程的所有学生的学号和姓名。 查询选课总学生最多的学生的姓名及其选课总学分。 查询选课门数最多的学生姓名及其选课门数。 查询选了其所在系开始所有课程的学生姓名。
Tianqing Zhang SCU 2
补充练习
• 查询所有没有被选过的课程。 • Select * from course c where not exists (select * from c_s where c.course_no=c_s.course_no);
Tianqing Zhang SCU
Tianqing Zhang SCU
4
查询选课总分最多的学生的姓名及其选课总学分。 select , sum (credit) from student s, c_s, course c where s.id=c_s.student_id and c_s.course_no=c.course_no group by s.id, having sum(credit)>= all (select sum(credit) from student s, c_s, course c where s.id=c_s.student_id and c_s.course_no=c.course_no group by s.id);
补充SQL练习
Tianqing Zhang School of Computer (School of Software选课数据库
– 学生(学号,姓名,性别,所在系,生日) – 课程(课程号,课程名,学分,开课系) – 选课(学号,课程号,成绩)
Tianqing Zhang SCU 7
相关主题