第一范文网 - 专业文章范例文档资料分享平台

sql练习题及答案

来源:用户分享 时间:2025/10/6 15:52:32 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

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的学生的信息。

搜索更多关于: sql练习题及答案 的文档
sql练习题及答案.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c3q6jh3jep683uyx9681999g5n13tny00urx_3.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top