收藏 分销(赏)

SELECT语句练习题答案.doc

上传人:精*** 文档编号:4137793 上传时间:2024-07-31 格式:DOC 页数:3 大小:62.05KB 下载积分:5 金币
下载 相关 举报
SELECT语句练习题答案.doc_第1页
第1页 / 共3页
SELECT语句练习题答案.doc_第2页
第2页 / 共3页


点击查看更多>>
资源描述
SELECT 语句练习题 有下列四个表: 1、学生表 S_NO S_NAME S_SEX S_BIRTHDAY CLASS 108 曾华 男 1905-5-22 95033 105 匡明 男 1905-5-18 95031 107 王丽 女 1905-5-7 95033 101 李军 男 1905-5-9 95033 109 王芳 女 1905-5-18 95031 103 陆君 男 1905-5-20 95031 2、教师表 T_NO T_NAME TSEX T_BIRTHDAY PROF DEPART 804 李诚 男 1958-12-2 副教授 计算机系 856 张旭 男 1969-3-12 讲师 电子工程系 825 王萍 女 1972-5-5 助教 计算机系 831 刘冰 女 1977-8-14 助教 电子工程系 3、课程表 C_NO C_NAME T_NO 3-105 计算机导论 825 3-245 操作系统 804 6-166 数据电路 856 9-888 高等数学 100 4、成绩表 S_NO C_NO DEGREE 103 3-245 86 105 3-245 75 109 3-245 68 103 3-105 92 105 3-105 88 109 3-105 76 101 3-105 64 107 3-105 91 108 3-105 78 101 6-166 85 107 6-106 79 108 6-166 81 Select 语句的最基本结构:Select …. From ….where order by:排序子句(ASC:升序,DESC:降序) like:模式匹配(通配符:% 可以匹配任意类型和长度的字符; _ 任意单个字符。 聚合函数(SUM AVG、COUNT、COUNT(*)、MAX、MIN) GROUP BY:分组 1、 查询Student表中的所有记录的S_NAME、S_SEX和Class列。 2、 查询教师所有的单位即不重复的Depart列。 3、 查询Student表的所有记录。 4、 查询Score表中成绩在60到80之间的所有记录。 5、 查询Score表中成绩为85,86或88的记录。 6、 查询Student表中“95031”班或性别为“女”的同学记录。 7、 以Class降序查询Student表的所有记录。 8、 以C_NO升序、Degree降序查询Score表的所有记录。 9、 查询“95031”班的学生人数。 10、查询Score表中的最高分的学生学号和课程号。 11、查询‘3-105’号课程的平均分。 12、查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。 13、查询最低分大于70,最高分小于90的S_NO列。 14、查询所有学生的S_NAME、C_NO和Degree列。 15、查询所有学生的S_NO、C_NAME和Degree列。 16、查询所有学生的S_NAME、C_NAME和Degree列。 17、查询“95033”班所选课程的平均分。 SQL语句练习题参考答案 1、 select S_NAME,S_SEX,Class from Student; 2、 select distinct depart from teacher; 3、 select S_NO as '学号',S_NAME as '姓名',S_SEX as '性别',S_BIRTHDAY as'出生日期',Class as'班号'from student; 或 select S_NO as 学号,S_NAME as 姓名,S_SEX as 性别,S_BIRTHDAY as 出生日期,Class as 班号 from student; 4、 select * from score where degree between 60 and 80; 或select * from score where degree>=60 and degree<=80; 5、 select * from score where degree in (85,86,88); 6、 select * from student where class='95031'or S_SEX='女'; 7、 select * from student order by class desc; 8、 select * from score order by C_NO asc ,degree desc; 或select * from score order by C_NO ,degree desc; 9、 select count(*) as CNT from student where class='95031'; 10、select S_NO as '学号',C_NO as '课程号', degree as '最高分' from score where degree=(select max(degree) from score) 11、select avg(degree)as 课程平均分 from score where C_NO='3-105'; 12、select C_NO,avg(degree) from score where C_NO like'3%'group by C_NO having   count(*) >5; 13、select S_NO from score group by S_NO having min(degree)>70 and max(degree)<90; 14、select student.S_NAME,score.C_NO,score.degree from student,score where student.S_NO=score.S_NO; 15、select x.S_NO,y.C_NAME,x.degree from score x,course y where x.C_NO=y.C_NO; 16、select x.S_NAME,y.C_NAME,z.degree from student x,course y,score z where x.S_NO=z.S_NO and z.C_NO=y.C_NO; 17、select y.C_NO,avg(y.degree) from student x,score y where x.S_NO=y.S_NO and x.class='95033'group by y.C_NO;
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 教育专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服