数据库经典查询题目

2014-11-24 14:01:21 · 作者: · 浏览: 0

数据库经典查询题目
设有学生选取修课程数据库
S(Sid, SNAME, AGE, SEX, DEPARTMENT, ADDRESS, BIRTHPLACE)
SC(Sid, Cid, GRADE)
C(Cid, CNAME, TEACHER)
(1) 李老师所教的课程号、课程名称;
select cid,cname
from c
where teacher = '李'
(2) 年龄大于23岁的女学生的学号和姓名;
select sid,sname
from s www.2cto.com
where s.age>23 and sex = '女'
(3) “李小波”所选修的全部课程名称;
select c.cname
from c
where c.cid in (
select sc.cid
from s,sc
where s.sid = sc.sid and s.sname = '李小波'
);
(4) 所有成绩都在80分以上的学生姓名及所在系;
select sname,department
from s
where sid in (
select sid from sc group by sid having min(grade)>=80
);
(5) 没有选修“操作 系统”课的学生的姓名;
select sname
from s
where s.sid not in (
select sc.sid from sc,c where sc.cid = c.cid and c.cname = '操作系统'
)
(6) 与“李小波”同乡的男生姓名及所在系;
select s.sname, s.department
from s www.2cto.com
where s.sex='男'
and s.birthplace = (
select s.birthplace
from s
where s.sname='李小波'
);
(7) 英语成绩比数学成绩好的学生;
(8) 选修同一门课程时,女生比男生成绩好的学生名单;
(9) 至少选修两门以上课程的学生姓名、性别;
(10)选修了李老师所讲课程的学生人数;
(11)没有选修李老师所讲课程的学生;
(12)“操作系统”课程得最高分的学生姓名、性别、所在系;

作者 radio123