当前位置:首页 > sql练习题及答案
where sno notin(select sno from cs)
(35) 查询每个学生及其选修课程的情况。
select cs.sno,course.*from cs,course where cs.cno=course.cno
(36) 查询选修2号课程且成绩在90分以上的所有学生的学号、姓名
select sno,sname from student where sno=(select sno from cs where cno=2 and cj>90)
(37) 查询每个学生的学号、姓名、选修的课程名及成绩。
select student.sno,sname,course.course,cs.cj from student,course,cs where student.sno=cs.sno and cs.cno=course.cno
(38) 查询与“刘晨”在同一个系学习的学生(分别用嵌套查询和连接查询)
----嵌套查询 select*from student where dept in (select dept from student where sname='刘晨')
----连接查询 select stu1.*from student as stu1,student as stu2 where stu1.dept=stu2.dept and stu2.sname='刘晨' ----exists查询 select*from student s1 whereexists( select*from student s2 where s1.dept=s2.dept and s2.sname='刘晨' )
(39) 查询选修了课程名为“信息系统”的学生学号和姓名
select sno,sname from student where sno in (select sno from cs where cno in(select cno from course where cname='信息系统'))
(40) 查询其他系中比信息系任意一个(其中某一个)学生年龄小的学生姓名和年龄
select sname,age from student where age (41) 查询其他系中比信息系所有学生年龄都小的学生姓名及年龄。分别用 ALL谓词和集函数 ----用ALL select sname,age from student where age (42) 查询所有选修了1号课程的学生姓名。(分别用嵌套查询和连查询) ----嵌套查询 select sname from student where sno in (select sno from cs where cno=1) ----连接查询 select sname from student,cs where student.sno=cs.sno and cs.cno=1 (43) 查询没有选修1号课程的学生姓名。 select sname from student where sno in (select sno from cs where cno!=1) (44) 查询选修了全部课程的学生姓名。 select sname from student wherenotexists (select*from course wherenotexists (select*from cs where cs.sno=student.sno and cs.cno=course.cno)) (45) 查询至少选修了学生95002选修的全部课程的学生号码。 selectdistinct sno from sc scx wherenotexists (select*from cs scy where scy.sno='95002'andnotexists (select*from sc scz where scz.sno=scx.sno and scz.cno=scy.cno)) (46) 查询计算机科学系的学生及年龄不大于19岁的学生的信息。 select*from student where dept='计算机科学系'or age<19 (47) 查询选修了课程1或者选修了课程2的学生的信息。
共分享92篇相关文档