数据的库1数据的查询.doc

上传人:李司机 文档编号:1189838 上传时间:2022-07-19 格式:DOC 页数:14 大小:309KB
返回 下载 相关 举报
数据的库1数据的查询.doc_第1页
第1页 / 共14页
数据的库1数据的查询.doc_第2页
第2页 / 共14页
数据的库1数据的查询.doc_第3页
第3页 / 共14页
数据的库1数据的查询.doc_第4页
第4页 / 共14页
数据的库1数据的查询.doc_第5页
第5页 / 共14页
点击查看更多>>
资源描述

《数据的库1数据的查询.doc》由会员分享,可在线阅读,更多相关《数据的库1数据的查询.doc(14页珍藏版)》请在三一办公上搜索。

1、实验一 数据库查询课程名称:数据库原理实验实验类型:验证型实验名称数据库查询学时4学时实验目的:使学生掌握SQL Server Query Analyzer的使用方法,加深对SQL和T-SQL语言的查询语句的理解。熟练掌握表的根本查询,连接查询和嵌套查询,以与掌握数据排序和数据分组的操作方法。实验原理:SELECT ALL|DISTINCT ,FROM ,WHERE GROUP BY HAVING order by ASC|DESC;实验方法:将查询需求用T-SQL语言表示;在SQL Server Query Analyzer的输入区中输入T-SQL查询语句;设置 Query Analyzer

2、的结果区为Standard Execute标准执行或Execute to Grid网格执行方式;发布执行命令,并在结果区中查看查询结果;如果结果不正确,要进展修改,直到正确为止。实验内容:1. 分别用带DISTINCT和不带DISTINCT关键字的SELELCT在student中进展查询.带distinct:Selectclass_id from student不带distinct:selectdistinct class_id from student2. 将teacher表中各教师的某某、教工号与工资按95发放的信息,并将工资按95发放后的列名改为预发工资select teacher_id

3、,teacher_name,salary*0.95 as 预发工资from teacher3. 查询course表中所有学分大于2并且成绩不与格的学生的信息.selectdistinct student.*from student,course,sc where student.student_id=sc.student_id and sc.course_id=course.course_id and course.credit2 and sc.grade80In:select*from student where student_id in(select student_id fromsc

4、where course_id=dep04_s001and grade80)exists:select*from student whereexists(select student_id from sc where student.student_id=sc.student_id andcourse_id=dep04_s001and grade80)10. 查询所有上计算机根底课程的学生的学号、选修课程号以与分数分别用连接,in和exists实现连接:select sc.*from sc,course where course.course_name=计算机根底and course.cour

5、se_id=sc.course_idIn:select student_id,course_id,grade from sc where course_id in(select course_id from course where course_name=计算机根底)exists:select student_id,course_id,grade from sc whereexists(select*from course where course_id=sc.course_id and course_name=计算机根底)11. 查询选修了课程名为“数据库根底的学生学号和某某分别用连接,i

6、n和exists实现连接:select student.student_id,student.student_name from sc,student,course where course.course_name=数据库开发技术and sc.student_id=student.student_id and course.course_id=sc.course_idIn:select student_id,student_name from student where student_id in(select student_id from sc where course_id=(selec

7、t course_id from course where course_name=数据库开发技术)exists:select student_id,student_name from student whereexists(select*from sc where sc.student_id=student.student_id and sc.course_id=(select course_id from course where course_name=数据库开发技术)12. 查询所有计算机系学生的学号、选修课程号以与分数分别用连接,in和exists实现连接:select sc.*fr

8、om sc,department,student where department.department_name=计算机科学and department.department_id=student.department_id and sc.student_id=student.student_idIn:select*from sc where student_id in(select student_id from student where department_id=(select department_id from department where department_name=计

9、算机科学)exists:select*from sc whereexists(select*from student where student.student_id =sc.student_id and student.department_id=(select department_id from department where department_name=计算机科)13查询每个dep_04系学生的总成绩、平均成绩, 仅显示平均成绩与格的学生的记录。select student.student_name ,sum(grade)as 总成绩,avg(grade)as 平均成绩from

10、sc, student,departmentwhere sc.student_id=student.student_id and student.department_id=department.Department_id and department.department_id=dep_04groupby student.student_id,student_namehavingavg(grade)6014查询“数据库开发技术的平均成绩selectavg(grade)as 数据库开发平均成绩from sc where course_id in(select course_id from co

11、urse where course_name=数据库开发技术)15按职称查询教师的平均工资,并按总工资降序排列select profession,avg(salary)as 平均工资,sum(salary)as 总工资from teacher groupby profession orderbysum(salary)desc附录1:教务管理数据库jwgl结构student表结构列名称数据类型长度允许空值说明Student_idChar8否学生学号Student_nameVarchar8否学生某某SexBit1否性别AgeInt4否年龄Class_id Char6否班级号Department_i

12、dChar6否系编号Addressvarchar50否家庭住址Course表字段名称数据类型长度允许空说明Course_idChar10否课程号Course_nameVarchar20否课程名称Book_idChar15否书标识SC表字段名称数据类型长度允许空说明Course_idChar10否课程号Student_idVarchar8否学生号gradeTinyint否成绩creditTinyint否学分Teacher表字段名称数据类型长度允许空说明Teacher_idChar9否教师编号Teacher_namenvarchar8否教师某某Department_idChar6否所在系号Prof

13、essionNvarchar16职称SexBit否性别phoneNvarchar15是adressNchar40是住址SalaryNumeric7.2是工资BirthSmalldatetime否出生日期PostalcodeNumeric6,0是 Book表字段名称数据类型长度允许空说明Book_idChar13否书号Book_nameVarchar30否书名Publish_panyVarchar50否Authornvarchar8是作者PriceNumeric5.2是价格Class表字段名称数据类型长度允许空说明Class_idChar6否班级号MonitorVarchar8是班主任某某Class_course表字段名称数据类型长度允许空说明Class_idChar6否班级号Course_idchar10否课程号Department表字段名称数据类型长度允许空说明Department_idChar6否系编号Department_namenvarchar20否系名称

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号