数据库习题

三个表

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 为取别名 可以用空格代替

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值