栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

数据库习题

数据库习题

三个表

1.学生关系表student表

stu_id      stu_namegenderbrith_date        dept_name
学号姓名性别出生日期专业

2.课程关系表course表

cour_idtitledept_namecredits
课程号课程名开课专业课程学分

3.学生选课表takes表

stu_idcour_idsemesteryeargrade
学生学号课程号学期学年成绩

题目:

1.在学生关系表中插入如下新生数据

('202141531120','张月昕','女','2001-01-01','计算机科学')

2.查找分数在70分以下的学生学号,姓名,课程名称以及成绩信息,并将找到的结果保存到新的关系表中

3.学生欧琼杰在2009年春季学期的unix系统编程课程考试舞弊,请将该学生该科成绩设置为零

4.将所有2010年春季学期选修了高等数学课程的所有选课记录全部删除

5.统计每个学生的选课门数和平均成绩,将结果定义为视图v_takes_count_avg_by_stuid

自己的答案:

1.
insert
into student(stu_id,stu_name,gender,brith_date,dept_name)
values('202141531120','张月昕','女','2001-01-01','计算机科学');
2.
select S.stu_id,S.stu_name,C.title,T.grade
into news
from student S,course C,takes T
where S.stu_id=T.stu_id and T.cour_id=C.cour_id and grade<70;
3.
update takes                                                           
set grade=0
where semester='春季学期'  and stu_id in(
    select S.stu_id
    from student S,takes T,course C
    where stu_name='欧琼杰' 
    and S.stu_id=T.stu_id
    and T.cour_id=C.cour_id
    and title='unix系统编程'
);
4.
delete 
from takes T,course as C
where T.cour_id =C.cour_id and semester='春季学期' and title ='高等数学';
5.
create view v_takes_count_avg_by_stuid
as
select stu_name, count(cour_id) as count,avg(grade) as  avg_grade
from takes T ,student S
where T.stu_id =S.stu_id
group by stu_name ;

不知对错,等老师讲咯

select 要查询的列

from 表名

where 条件  有四种子查询 in子查询、带有比较运算符的子查询、代any(some)或all的子查询、exist(存在)子查询,其中exist的返回值为ture or false

group by 分组 having 条件

order by 排序(最后显示的时候)分为ASO (升序)和DESC(降序),默认升序

顺序为 F W  G H S O

聚集函数:

where中不能用聚集函数 distinct为去重,聚集函数只能用于select 和having中

count(* )统计所有元组个数
count(【distinct】列名)统计一列中值的个数
sum(【distinct】列名)      求和
avg(【distinct】列名)求平均        
max(【distinct】列名)求最大值        
min(【distinct】列名)        求最小值

as 为取别名 可以用空格代替

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/780977.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号