数据库查询面试题
设有学生选取修课程数据库: 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 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='李小波' );

浙公网安备 33010602011771号