数据库sql查询语句练习 2015.6.6修正.doc

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
数据库sql查询语句练习 2015.6.6修正

现在有一教学管理系统,具体的关系模式如下: 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 写出上述表的建表语句。 命令: DML 给出相应的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 where name not in (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(*) as 男生人数,count(distinct class) as 班级数 from student where sex=男; 列出存在有85分以上成绩的课程编号。 命令: select distinct cno from score where degree85; 输出95001班级的学生人数 命令: select count(*) from student where class=95001; 输出‘3-105’号课程的平均分 命令:select avg(degree) 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(degreee),max(degreee),min(degreee) from score where cno in(select cno from score where cno like 3% group by cno having count(cno)=5); 方法二:select cno,avg(degree),max(degree),min(degree) from score group by cno having cno like 3% and count(cno)=5; 输出所选修课程中最低分大于70分且最高分小于90分的学生学号及学生姓名 命令: 子查询:Select no,name from student where no in(select no from score group by no having min(degree)70 and max(d

文档评论(0)

dajuhyy + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档