ImageVerifierCode 换一换
格式:DOCX , 页数:12 ,大小:69.58KB ,
资源ID:25283418      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/25283418.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(sql练习题+答案.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

sql练习题+答案.docx

1、sql练习题+答案sql练习题+答案(一)新建以下几个表student(学生表):snosnamesexdeptbirthage其中约束如下:(1)学号不能存在相同的(2)名字为非空(3)性别的值只能是男或女(4)系包括这几个:信息系,计算机科学系,数学系,管理系,中文系,外语系,法学系(5)出生日期为日期格式(6)年龄为数值型,且在0100之间(1)(2)(3)select distinct dept from student(4)查询选修了课程的学生学号。select sno from cs where cno is not null(5)查询所有年龄在20岁以下的学生姓名及其年龄。sel

2、ect sname,age from student where age 20(6)查询年龄在2023岁(包括20岁和23岁)之间的学生的姓名、系别和年龄。select sname,dept,age from student where age between 20 and 23(7)查询年龄不在2023岁之间的学生姓名、系别和年龄。select sname,dept,age from student where age23(8)查询信息系、数学系和计算机科学系生的姓名和性别。select sname,sex from student where dept=信息系 or dept=数学系 or

3、 dept=计算机科学系(9)查询既不是信息系、数学系,也不是计算机科学系的学生的姓名和性别。select sname,sex from student where dept!=信息系 and dept!=数学系 and dept!=计算机科学系(10)查询所有姓刘学生的姓名、学号和性别。select sname,sno,sex from student where sname like(刘%)(11)查询学号为2009011的学生的详细情况。(具体的学号值根据表中数据确定)select * from student where sno=5(12)查询姓“欧阳”且全名为三个汉字的学生姓名sel

4、ect sname from student where sname like(欧阳_)(13)查询名字中第2个字为“晨”字的学生的姓名和学号select sname,sno from student where sname like(_晨)(14)查询所有不姓刘的学生姓名。select sname,sno from student where sname not like(刘%)(15)查询sql课程的课程号和学分。select cno from course where cname=sql(16)查询以DB_开头,且倒数第3个字符为 i的课程的详细情况。select * from cour

5、se where cname like(DB_%i_)(17)查询缺少成绩的学生的学号和相应的课程号。select sno,cno from cs where cj is null(18)查所有有成绩的学生学号和课程号。select sno,cno from cs where cj is not null(19)查询计算机系年龄在20岁以下的学生姓名。select sname from student where age 3(30)查询有3门以上课程是90分以上的学生的学号及(90分以上的)课程数。select sno, count(cno) as 课程数 from cs where cj90

6、 group by sno having count(cno)=3(31)查询学生2006011选修课程的总学分。select sum(course) from course,cs where o=cs.sno and cs.sno=2006011(32)查询每个学生选修课程的总学分。select sno,sum(cj)from cs,coursewhere o=ogroup by snounionselect sno, 0 from studentwhere sno not in (select sno from cs) (33)查询每个学生及其选修课程的情况。select cs.sno,c

7、ourse.* from cs,course where o=o (34)查询选修2号课程且成绩在90分以上的所有学生的学号、姓名select sno,sname from student where sno=(select sno from cs where cno=2 and cj90)(35)查询每个学生的学号、姓名、选修的课程名及成绩。select student.sno,sname,course.course,cs.cj from student,course,cs where student.sno=cs.sno and o=o(36)查询与“刘晨”在同一个系学习的学生(分别用嵌套

8、查询和连接查询)-嵌套查询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 where exists(select * from student s2 where s1.dept=s2.dept ands2.sname=刘晨 )(3

9、7)查询选修了课程名为“信息系统”的学生学号和姓名select sno,sname from student where sno in(select sno from cs where cno in(select cno from course where cname=信息系统)(38)查询其他系中比信息系任意一个(其中某一个)学生年龄小的学生姓名和年龄select sname,age from student where age any(select age from student where dept=信息系)(39)查询其他系中比信息系所有学生年龄都小的学生姓名及年龄。分别用ALL谓词

10、和集函数-用ALLselect sname,age from student where age all(select age from student where dept=信息系)-聚合函数select sname,age from student where age (select min(age) from student where dept=信息系)(40)查询所有选修了1号课程的学生姓名。(分别用嵌套查询和连查询)-嵌套查询select sname from student where sno in(select sno from cs where cno=1)-连接查询sele

11、ct sname from student,cs where student.sno=cs.sno and o=1(41)查询没有选修1号课程的学生姓名。select sname from student where sno in(select sno from cs where cno!=1)(42)查询选修了全部课程的学生姓名。select sname from student where not exists(select * from course where not exists (select * from cs where cs.sno=student.sno ando=o)(4

12、3)查询至少选修了学生95002选修的全部课程的学生号码。select distinct sno from sc scx where not exists(select * from cs scy where scy.sno=95002 and not exists(select * from sc scz where scz.sno=scx.sno and o=o)(44)查询计算机科学系的学生及年龄不大于19岁的学生的信息。select * from student where dept=计算机科学系 or age19(45)查询选修了课程1或者选修了课程2的学生的信息。select st

13、udent.* from student,cs where student.sno = cs.sno and (o=1 or o=2)(46)查询计算机科学系中年龄不大于19岁的学生的信息。select * from student where age19(49)通过查询求学号为1学生的总分和平均分。select sum(cj) as 总分,avg(cj)平均分 from cs where sno=1(50)求出每个系的学生数量select dept,count(sno) as 学生个数 from student group by dept(51)查询平均成绩大于85的学生学号及平均成绩。se

14、lect sno,avg(cj) from cs group by sno having avg(cj)85(52)要求查寻学生的所有信息,并且查询的信息按照年龄由高到低排序,如果年龄相等,则按照学号从低到高排序select * from student order by age desc,sno asc1在SELECT语句中DISTINCT、ORDER BY、GROUP BY和HAVING子句的功能各是什么?答 各子句的功能如下。DISTINCT:查询唯一结果。ORDER BY:使查询结果有序显示。GROUP BY:对查询结果进行分组。HAVING:筛选分组结果。2在一个SELECT语句中,当WHERE子句、GROUP BY子句和HAVING子句同时出现在一个查询中时,SQL的执行顺序如何?答 其执行顺序如下:(1)执行WHERE子句,从表中选取行。(2)由GROUP BY对选取的行进行分组。(3)执行聚合函数。(4)执行HAVING子句选取满足条件的分组。

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1