- 1、本文档共14页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
数据库sql查询语句练习2_习题_结果(单世民)精选
现在有一教学管理系统,具体的关系模式如下:
Student (no, name, sex, birthday, class)
Teacher (no, name, sex, birthday, prof, depart)
Course (cno, cname, tno)
Score (no, cno, degree)
其中表中包含如下数据:
Course表:
Score表:
Student表:
Teacher表:
根据上面描述完成下面问题:
(注意:注意保存脚本,尤其是DDL和DML,以便进行数据还原)
DDL
写出上述表的建表语句。
给出相应的INSERT语句来完成题中给出数据的插入。
单表查询
以class降序输出student的所有记录(student表全部属性)
命令:select * from Student order by class desc;
列出教师所在的单位depart(不重复)。
命令:select distinct depart from Teacher;
列出student表中所有记录的name、sex和class列
命令:select name,sex,class from Student;
输出student中不姓王的同学的姓名。
命令:select name from Student except select name from Student where name like 王%;或
select name from Student where name not like 王%;
输出成绩为85或86或88或在60-80之间的记录(no,cno,degree)
命令:select no,cno,DEGREE from Score where degree=85 or degree=86 or degree=88 or degree between 60 and 80;
输出班级为95001或性别为‘女’ 的同学(student表全部属性)
命令:select * from Student where class=95001 or sex=女;
以cno升序、degree降序输出score的所有记录。(score表全部属性)
命令:select * from Score order by cno asc,degree desc;
输出男生人数及这些男生分布在多少个班级中
命令:select COUNT(*),count(distinct class) from Student where sex=男;
列出存在有85分以上成绩的课程编号。
命令:select distinct cno from Score where degree85;
输出95001班级的学生人数
命令:select COUNT(*) from Student where class=95001;
输出‘3-105’号课程的平均分
命令:select avg(cast(degree as float)) from Score where cno=3-105;
输出student中最大和最小的birthday日期值
命令:select MAX(birthday),MIN(birthday) from Student;
显示95001和95004班全体学生的全部个人信息(不包括选课)。(student表全部属性)
命令:select * from Student where class=95001 or class=95004;
聚合查询
输出至少有5个同学选修的并以3开头的课程的课程号,课程平均分,课程最高分,课程最低分。
命令:select cno,avg(cast(degree as float)),MAX(degree),MIN(degree) from Score where cno like 3% group by cno having COUNT(cno)5;
或者:
select cno,AVG(cast(DEGREE as float)),MAX(degree),MIN(DEGREE) from Score group by cno having COUNT(cno)=5 and cno like 3%
输出所选修课程中最低分大于70分且最高分小于90分的学生学号及学生姓名
命令:select Student.no,name from Student join Score on Student.no=Score.no group by Student.no,name having MAX(Score.degree)90 and MIN(Score.degree)70;
显示所教课程选修人数多于5人的教
您可能关注的文档
最近下载
- 政府会计准则试题.pdf VIP
- 2025年江西省中考语文模拟卷(二)(含答案) .pdf VIP
- 综合与实践 低碳生活(课件)2024-2025学年度人教版数学七年级下册.pptx VIP
- 关于护理垂直管理体系的工作方案.docx VIP
- 实训3数据备份的概念,掌握使用Windows Server Backup备份和恢复数据.docx VIP
- 社区网格化管理工作小结.doc VIP
- 水利水电工程安全监测单元工程施工质量验收评定标准.pdf VIP
- 东方黄粱梦(原曲:仙剑赋)钢琴谱钢琴简谱 数字谱 钢琴双手简谱.pdf VIP
- 《肾上腺皮质功能监测》课件.ppt VIP
- 注册安全工程师知识点总结(法律法规).docx
文档评论(0)