码迷,mamicode.com
首页 > 其他好文 > 详细

第6此实验

时间:2016-04-25 13:12:10      阅读:362      评论:0      收藏:0      [点我收藏+]

标签:

实验六

一.实验目的:

熟练掌握使用SELECT语句进行数据查询。

二.实验内容:(所有题写到实验报告中)

一)对数据库stuinfo进行如下操作:

1. 查询student表中的学号、姓名和年龄并为列设置别名,结果按学号升序排。

USE stuinfo;

 select sno as 学号,sname as 姓名 from student order by sno asc

2. 查询班级(要求不重复)

select DISTINCT * from course

3. 在student表查询姓“王”的学生信息。

USE stuinfo;

 select * from student where sname like ‘王%‘

4.查询成绩在80-100之间的学号、课程号及成绩,结果先按课程号升序排,课程号一样的再按成绩降序排。

USE stuinfo;

 select sno , cno , degree from

 score

 where score.degree between 80 and 100

 order by cno asc ,degree desc

 

5. 查询所有缺考的学生的学号及课程号。

USE stuinfo;

 select sno , cno   from

 score

where degree = 0

6. 查询 ‘3-105’课的选课人数、最高分、最低分和平均分。

USE stuinfo;

 select

  COUNT(*)  as 选课人数, 

  MAX(degree) as 最高分,

  MIN(degree) as 最低分,

  AVG(degree) as 平均分

 

  from

 score

where cno = ‘3-105‘

 

7.查询每位同学的平均成绩,包括学号和平均成绩两列,结果按学号升序排。

USE stuinfo;

 select

 sno,

 AVG(degree) as 平均成绩

  from

 score

group by sno

order by sno asc

8. 查询各班各门课的平均成绩,包括班号、课程号和平均成绩三列,结果先按班升序排,班一样的再按课程号升序排。

USE stuinfo;

 Select

 student.sclass,

 score.cno,

 AVG(score.degree) as 平均成绩

  from

 score left join student on student.sno=score.sno

group by sclass , cno

order by sclass asc,cno desc

 

9. 查询score表中至少有5名学生选修的课程号及平均分。

USE stuinfo;

 select distinct cno,AVG(degree) as 平均分

 from score 

 group by cno having  score.cno in (select cno from score group by cno having count(cno) > 5 )

 

10. 查询其平均分高于80的学生的学号,姓名和平均分。

USE stuinfo;

 select distinct score.sno as 学号,student.sname as 姓名,AVG(degree) as 平均分

 from score  

 left join student on student.sno = score.sno

 group by score.sno , student.sname

 having 

 score.sno

 in

 (select sno from score group by sno having AVG(degree) > 80 )

 

11. 查询“95031”班所选课程的平均分,包括课程名和平均分。

USE stuinfo;

select AVG(score.degree) As 平均分,course.cname as 课程名

from score

left join course on course.cno=score.cno

left join student on student.sno=score.sno

where student.sclass = 95031

group by course.cname

12. 查询所有教师的任课情况,包括教师姓名和课程名两列,如果某位教师没有任课则课程名列显示NULL。

use stuinfo;

select teacher.tname,course.cname

from teacher left join course on course.tno=teacher.tno

 

13. 查询其最低分大于70,最高分小于90的学生的学号、所选课程号及其分数。

use stuinfo;

select sno,cno,degree

from score

group by sno,cno,degree

having MIN(degree)>70 and MAX(degree)<90

14. 查询成绩高于所选课平均分的学生学号、姓名、课程号和成绩。

15. 查询每门课最高分的课程名、学生姓名和成绩。

16. 查询选修其课程的学生人数多于5人的教师姓名。

17. 查询没选“张旭”教师课的学生成绩,并按成绩递增排列。

18. 查询没有任课的教师的姓名。

19. 查询没有选修"6-166"课程的学生的学号和姓名。

20. 查询出所有男生信息放入NS表中。

21. 删除没人选的课程。

22. 将“95031”班学生的成绩全部减去10分。

二)对订单管理库ordermanagement进行下列查询

ordermanagement数据库中有三个表,其结构如下:(加下划线的为主键)

客户表customer(客户号,客户名,地址,电话)

订单表order_list(订单号,客户号,订购日期)

订单明细表Order_detail(订单号,器件号,器件名,单价,数量)

使用SELECT语句完成下列查询:

1. 查询2001年的所有订单信息(订单号,客户号,订购日期)。

2. 查询订单明细中有哪些器件(即查询不重复的器件号和器件名)。

3.查询客户名为“三益贸易公司”的订购单明细(订单号、器件号、器件名、单价和数量),

查询结果先按“订单号”升序排,同一订单的再按“单价”降序排。

4.查询目前没有订单的客户信息。

5.查询客户名中有“科技”字样的客户信息。

6. 查询每笔订单的订单号和总金额,查询结果按订单号升序排,查询结果存入表ZJE中。

7. 查询订单数量超过5笔的客户号及订单数量,查询结果按订单数量降序排。

8. 查询每种器件中单价最低的订单明细(订单号、器件号、器件名、单价和数量)。

9. 对表order_detail建立查询,把“订单号”的尾部字母相同且“器件号”相同的订单合并

成一张订单,新的“订单号”取原来订单号的尾部字母,器件号不变,“单价”取最低价,

“数量”取合计,查询结果先按新的“订单号”升序排,再按“器件号”升序排。

10. 查询销售总数量最多的三种器件及其总数量。

 

第6此实验

标签:

原文地址:http://www.cnblogs.com/yang95/p/5430379.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!