数据库上机-4

数据库实验四


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  14. 删除没人选的课程。

  15. 将“95031”班学生的成绩全部减去10分。
    二)对订单管理库ordermanagement进行下列查询

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. 查询销售总数量最多的三种器件及其总数量。
USE stuinfo
/1
SELECT sno as 学号,sname as 姓名,2019-year(sbirthday) as 年龄 FROM student
ORDER BY sno
/2
SELECT DISTINCT sclass FROM STUDENT
/3
SELECT * FROM STUDENT
WHERE sname LIKE '王%'
/4
SELECT sno,cno,degree 
FROM score
ORDER BY cno,degree desc
/5
SELECT sno,cno
FROM score
WHERE degree is null
/6
SELECT COUNT(DISTINCT sno) 选课人数,max(degree) 最高分,min(degree) 最低分,avg(degree) 平均分
from score
where cno='3-105'
/7
select sno 学号,avg(degree) 平均成绩
from score
group by sno
order by sno
/8
select sclass 班号,cno 课程号,avg(degree) 平均成绩
from student,score where score.sno=student.sno
group by sclass,cno
order by sclass,cno
/9
select cno,avg(degree) avg
from score
group by cno
having count (distinct sno)>=5
/10
select student.sno,sname,avg(degree) avg
from student,score
where score.sno=student.sno
group by student.sname,student.sno
having avg(degree)>80
/11
select cname,avg(degree) 平均分
from score,student,course
where score.sno=student.sno and score.cno=course.cno
group by sclass,cname
having sclass='95031'
/12
select tname,cname
from teacher left join course
on  teacher.tno=course.tno
group by tname,cname
/13
select sno as 学号,cno as 课程号,degree as 成绩
from score a
where (select min(degree) from score b where a.sno=b.sno)>70 and (select max(degree) from score c where a.sno=c.sno)<90 and degree is not null
/14
select student.sno,sname,cno,degree
from student,score a
where student.sno=a.sno and degree>(select avg(degree) from score b group by cno having a.cno=b.cno)
/15
select cname,sname,degree
from student,course,score a
where student.sno=a.sno and course.cno=a.cno and degree=(select max(degree) from score b group by cno having a.cno=b.cno)
/16
select tname
from course,teacher
where teacher.tno=course.tno and (select count(sno) from score group by cno having score.cno=course.cno)>5
/17
select student.sno,score.degree
from student,teacher,score,course
where student.sno=score.sno and teacher.tno=course.tno and score.cno=course.cno and tname!='张旭'
order by degree
/18
select tname
from teacher left join course
on teacher.tno=course.tno 
where course.tno is null
/19
select distinct student.sno,sname
from score,student
where score.sno=student.sno and cno!='6-166'
/20
select  student.sno as 学号,student.sname as 学生姓名,ssex as 性别,sbirthday as 生日,sclass as 班级,cname as 课程
,degree as 成绩
into pS
from  student,score,course
where student.sno=score.sno and ssex='男' and course.cno=score.cno
order by student.sno
/21
delete course
where course.cno not in(select cno from score)
/22
update score
set degree=degree-10
from student,score
where student.sno=score.sno and sclass='95031'
/
/1
select *
from order_list where year(订购日期)='2001'
/2
select distinct 器件号,器件名
from order_detail
/3
select order_detail.订单号,器件号,器件名,单价,数量
from order_detail,customer,order_list 
where customer.客户号=order_list.客户号 and order_list.订单号=order_detail. 订单号 and customer.客户名='三益贸易公司'
order by order_detail.订单号,单价 DESC
/4
select *
from customer
where 客户号 not in(select 客户号 from order_list)
/5
select *
from customer
where 客户名 like '%科技%'
/6
select order_detail.订单号,sum(单价*数量) as 总金额
into ZJE
from order_detail
group by order_detail.订单号
order by order_detail.订单号
/7
select distinct 客户号,count(客户号) as 订单数量
from order_list
group by 客户号
having count(客户号)>5
order by 订单数量 desc
/8
select *
from order_detail a
where 单价=(select min(单价) from order_detail b where a.器件号=b.器件号)
/9
select right(order_detail.订单号,1) as 订单号,器件号,MIN(单价) as 单价,SUM(数量) as 数量
from order_detail
group by right(order_detail.订单号,1),器件号
order by 订单号,器件号
/10
select top 3 器件号,sum(数量) as 总数量
from order_detail
group by 器件号
order by sum(数量) desc
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值