阿花儿】重庆专升本-数据库专项训练【答案】
数据库专项训练
某数据库中存在以下几个关系
Student表 Sno,Sname,sex,Birthday,Tall,Class,Major 其中Birthday为Date型数据,Tall为Int型数据
Teacher表 Tno,Tname,sex,Age,Sal,Dept 其中Age和Sal为Int型数据
Score表 Num,Sno,Subject,Score 其中Score为Int型数据
1.在Student表中插入一条学生信息,(S0001,阿花儿,男,1994年10月28日,2班,计算机)
【参考答案】
insert into Student
values("S0001","阿花儿","男",#1994/10/28#,"2班","计算机")
2.在Teacher表中插入一条老师信息,(T0001,王雨霜,女,24,英语),工资未定。
【参考答案】
insert into Teacher(Tno,Tname,sex,Age,Dept)
values("T0001","王雨霜","女",24, "英语")
3.在Student表中删除一条姓名为“阿花儿”的学生的信息。
【参考答案】
delete from Student
where Sname="阿花儿"
4.在Teacher表中删除年龄大于25岁的男老师的信息。
【参考答案】
delete from Teacher
where sex="男" and Age>25
5.在Teacher表中,将王雨霜老师的年龄增加5岁,将王雨霜老师的工资增加5000元。
【参考答案】
update Teacher
set Age=Age+5,sal=sal+5000
where Tname="王雨霜"
6.在Score表中删除计算机或者英语小于60的学生的信息。
【参考答案】
delete from Score
where (Subject="计算机" and Score<60) or (Subject="英语" and Score<60)
或者
delete form Score
where (Subject="计算机" or Subject="英语") and (Score<60)
7.删除Teacher关系。
【参考答案】
Drop table Teacher
8.新增一个Teacher关系,关系字段为Tno,Tname,Age,Sal,Dept,其中Age和Sal为Int型数据。
【参考答案】
Create Table Teacher
(Tno char(32),
Tname char(32),
Age Int,
Sal Int,
Dept Char(32))
//char(32)可以写成Text(32) String(32) Vchar(32)
9.在Student表中查询出90后的女学生的信息。
【参考答案】
select *
from Student
where Year(Birthday) between 1990 and 1999 // where Year(Birthday)>=1990 and Year(Birthday)<=1999
或者
select *
from student
where Birthday between #1990/1/1# and #1999/12/31#
10.从Student表中查询出所有姓“王”的学生的信息。
【参考答案】
select *
from Student
where Sname like "赵*"
11.统计出Score表中数学成绩大于60分的学生的人数。
【参考答案】
select count(*) as 人数
from Score
where Dept="数学" and Score>60
12.统计出Score表中数学成绩大于60分的学生的学号、姓名、班级、数学成绩等信息。
【参考答案】
select Student.Sno,Student.Sname,Student.Class,Score.Score
from Student,Score
where Score.Score>60 and Score.subject="数学"
13.统计出Score表中数学的最高成绩,最低成绩。
【参考答案】
select max(Score) as 最高成绩,min(Score) as 最低成绩
from Score
where Subject="数学"
14.统计出全班数学成绩大于60分的学生的学号、姓名、班级、科目、数学成绩等信息。
【参考答案】
select Student.Sno,Student.Sname,Student.Class,Score.Subject,Score.Score
from Student,Score
where Student.Sno=Score.Sno and (Score.Subject="数学" and Score.Score>60)
15.统计出全班每个男生的姓名及其年龄大小。(根据出生日期进行计算)
【参考答案】
select Sname, Year(Date()) - Year(Birthday) as Age
From Student
where sex = "男"
16.字Student表中查询出所有女生的信息,并按照出生日期进行降序排序。
【参考答案】
select *
from Student
where sex= "女"
order by Birthday desc
17.在Student表中统计出所有男生的平均身高,最高身高和人数。
【参考答案】
select avg(Tall) as 平均身高,max(Tall) as 最高身高,count(*) as 男生人数
from Student
where sex="男"
18.统计出学生的平均年龄。
【参考答案】
select avg(year(date())-year(Birthday)) as 平均年龄
from Student
19.分别统计出男生和女生的平均身高、最高身高。
【参考答案】
select sex,avg(Tall) as 平均身高,max(Tall) as 最高身高
from Student
group by sex
20.分别统计出男生和女生的人数。
【参考答案】
select sex,count(*) as 人数
from Student
group by sex