sql题目复习

来源:互联网 发布:ubuntu安装win10 编辑:程序博客网 时间:2024/05/21 09:41

题目一:

为管理岗位业务培训信息,建立3个表:
S (Sid,SN,SD,SA)    Sid,SN,SD,SA 分别代表学号、学员姓名、所属单位、学员年龄
C (Cid,CN,CTeacher)    Cid,CN 分别代表课程编号、课程名称、cteacher任课老师(任课老师列与题目一无关,主要为题目二所添加
SC ( Sid,Cid,G )    Sid,Cid,G 分别代表学号、所选修的课程编号、学习成绩

--1. 使用标准SQL嵌套语句查询选修课程名称为 税收基础 的学员学号和姓名select sid,sn from tab_s where sid in (select sid from tab_sc where cid=(select cid from tab_c where cn='税收基础'))--2. 使用标准SQL嵌套语句查询选修课程编号为’C2’的学员姓名和所属单位select sn,sd from tab_s where sid in (select sid from tab_sc where cid=2)--3. 使用标准SQL嵌套语句查询不选修课程编号为’C5’的学员姓名和所属单位select sn,sd from tab_s where sid not in (select sid from tab_sc where cid=2)--4. 使用标准SQL嵌套语句查询选修全部课程的学员姓名和所属单位(不会做,先看看第6题)select sid,sd from tab_swhere sid in (select sid from tab_sc group by sid having count(sid)=(select count(*) from tab_c))--5. 查询选修了课程的学员人数select count(distinct sid) from tab_sc--6. 查询选修课程超过5门的学员学号和所属单位select sid,sd from tab_swhere sid in (select sid from tab_sc group by sid having count(sid)>5)


题目二:

--1. 找出没有选修过“英语老师”老师讲授课程的所有学生姓名select sn from tab_s where sid not in(select distinct sid from tab_sc where cid=(select cid from tab_c where cteacher='英语老师'))--2. 列出有二门以上(含两门)不及格课程的学生姓名及其平均成绩--第一步(找出两门(含两门)不及格课程的学生id)--select sid from tab_sc where g<60 group by sid having count(distinct cid)>=2select tab_S.sid,tab_s.sn,AVG_SCGRADE=AVG(tab_sc.g)from tab_s,tab_sc , (select sid from tab_sc where g<60 group by sid having count(distinct cid)>=2) A  where tab_S.Sid=A.sid and tab_sc.Sid=A.sidgroup by tab_s.sid,tab_s.sn--3. 列出既学过“1”号课程,又学过“2”号课程的所有学生姓名select sid,sn from tab_swhere sid in(select sid from tab_scwhere cid in (1,2)group by sidhaving count(distinct cid)=2)--4.列出“1”号课成绩比“2”号同学该门课成绩高的所有学生的学号





题目转载自:http://www.cnblogs.com/finejob/articles/974900.html

以上为自己整理、复习所做。答案仅供参考。