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

sql练习题及答案

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

(12) 查询所有姓刘学生的姓名、学号和性别。

select sname,sno,sex from student where sname like('刘%')

(13) 查询学号为2009011的学生的详细情况。(具体的学号值根据表中数据确定)

select*from student where sno=5

(14) 查询姓“欧阳”且全名为三个汉字的学生姓名

select sname from student where sname like('欧阳_')

(15) 查询名字中第2个字为“晨”字的学生的姓名和学号

select sname,sno from student where sname like('_晨')

(16) 查询所有不姓刘的学生姓名。

select sname,sno from student where sname notlike('刘%')

(17) 查询sql课程的课程号和学分。

select cno from course where cname='sql'

(18) 查询以\开头,且倒数第3个字符为 i的课程的详细情况。

select*from course where cname like('DB[_]%i__')

(19) 查询缺少成绩的学生的学号和相应的课程号。

select sno,cno from cs where cj isnull

(20) 查所有有成绩的学生学号和课程号。

select sno,cno from cs where cj isnotnull

(21) 查询计算机系年龄在20岁以下的学生姓名。

select sname from student where age < 20 and dept='计算机科学系'

(22) 查询信息系、数学系和计算机科学系学生的姓名和性别。(使用多个条

件表达式)

select sname,sex from student where dept='信息系'or dept='数学系'or dept='计算机科学系'

(23) 查询年龄在20~23岁(包括20岁和23岁)之间的学生的姓名、系别和年

龄。(使用多个条件表达式)

select sname,dept,age from student where age between 20 and 23

(24) 查询选修了3号课程的学生的学号及其成绩,查询结果按分数降序排列。

select sno,cj from cs where cno=3 orderby cj

desc

(25) 查询全体学生情况,查询结果按所在系的系号升序排列,同一系中的学

生按年龄降序排列。

select*from student orderby dept asc,age desc

(26) 查询学生总人数。

selectcount(*)from student

(27) 查询选修了课程的学生人数。

selectcount(sno)from cs where cno isnotnull

(28) 计算1号课程的学生平均成绩。

selectavg(cj)from cs where cno=1

(29) 查询选修1号课程的学生最高分数。

selectmax(cj)from cs where cno=1

(30) 求各个课程号及相应的选课人数。

select course.cno,count(cs.sno)from course leftjoin cs

on course.cno=cs.cno groupby course.cno

(31) 查询选修了3门以上课程的学生学号。

select sno,count(cno)from cs groupby sno havingcount(cno)>3

(32) 查询有3门以上课程是90分以上的学生的学号及(90分以上的)课程数。

select sno,count(cno)as'课程数'from cs where cj>90 groupby sno havingcount(cno)>=3

(33) 查询学生2006011选修课程的总学分。

selectsum(course)from course,cs where course.cno=cs.sno and cs.sno=2006011

(34) 查询每个学生选修课程的总学分。

select sno,sum(cj)from cs,course where cs.cno=course.cno groupby sno union select sno, 0 from student

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