一.SQL语言查询选修了全部课程的学生的学号和姓名. 两种解决途径: 第一种: 我们可以表示为在SC表中某个学生选修的课程数等于C表中课程总数.相应的SQL语言如下: select S#,SNAME from S where S# in (select S# from SC group by S# --根据Sno分组,统计每个学生选修了几门课程.如果等于C表课程的总数,就是我们要找的S# having count(*) = (select count(*) from C))--统计C表中共有几门
前几天求职面试,有一道SQL题:给出三个表:学生.课程.成绩,求选修了所有课程的学生. 一道看似很简单的问题,把我难住了,我改了又改,涂涂画画,抓耳挠腮,因为试卷没有多少空白位置了,最后只好放弃.心情大受影响,尽管最后还是获得offer. 但是心中有愧呀! 于是在机器上试了试: 先建好表 use test; go create table student(sno varchar(50) not null,name varchar(50) not null); insert into studen
23.查询"张旭"教师任课的学生成绩. select * from score s where cno in ( select cno from course where tno in( select tno from teacher where tname = '张旭')) 24.查询选修某课程的同学人数多于5人的教师姓名. select tname from teacher where tno in ( select tno from course where cno in ( s
select sname from student where not exists (select * from course where not exists (select * from sc where sno =student.sno and cno=course.cno); 最内部的 select * from sc where sno=student.sno and cno = course.cno是查询出所有已经选择过课程的学生及相应课程,select * from cour
29.查询选修编号为"3-105"课程且成绩至少高于选修编号为"3-245"的同学的Cno.Sno和Degree,并按Degree从高到低次序排序. select tname,prof from teacher where depart = '计算机系' and prof not in ( select prof from teacher where depart = '电子工程系') 30.查询选修编号为"3-105"且成绩高于选修编号为&q
给出数据库(sco)如下图: 查出每门课程成绩最高的学生 select b.id,b.kemu,b.name,b.chengji from (select kemu,max(chengji) maxc from sco group by kemu) a,sco b where a.kemu=b.kemu and a.maxc = b.chengji; 其中 select kemu,max(chengji) maxc from sco group by kemu 表示查出每科最高成绩和对应科目 查