一.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
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
20.查询score中选学多门课程的同学中分数为非最高分成绩的记录. select * from score a where sno in ( select sno from score group by sno having count(1)>1) and a.degree<(select max(degree) from score b where a.cno=b.cno )
给出数据库(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 表示查出每科最高成绩和对应科目 查
1.相关数据表 Score表 [User]表 SQL语句例如以下: --查询出各科成绩最好的学生信息 --自连接 --SELECT TOP 1 * FROM Score B WHERE B.ScoreName = '数学' ORDER BY B.Score DESC SELECT A.ID,U.Name,A.ScoreName,A.Score FROM Score A,[User]U WHERE UID IN (SELECT TOP 1 UID FR