利用游标实现利用游标实现

来源:百度知道 编辑:UC知道 时间:2024/05/12 17:15:46
利用游标实现
对于学生-课程数据库(包括Student、Course和SC三个表),至少编写分别完成以下功能的使用游标的两个存储过程:
(1)统计并显示离散数学的成绩分布情况,即按照大于90、80~89、70~79、60~69和60以下,统计各分数段人数。
(2)将所有成绩按如下要求更改:成绩大于90的改为95、成绩在80~89之间的改为85、成绩在70~79之间的改为75,成绩在60~69之间的改为65,成绩在60以下的改为45。
本问题可以用SQL其他语句实现,但是在此要求必须用游标实现,谢谢!此外表的建立可以根据要求程序自己随意

不需要游标

问题1:
select c.科目,
sum(case when sc.成绩 >=90 then 1 else 0 end) as '>=90',
sum(case when sc.成绩 >=80 then 1 else 0 end) as '>=80',
sum(case when sc.成绩 >=70 then 1 else 0 end) as '>=70',
sum(case when sc.成绩 >=60 then 1 else 0 end) as '>=60',
sum(case when sc.成绩 <60 then 1 else 0 end) as '<60'
from Course c ,sc
where c.C_ID=sc.C_ID and c.科目=N'离散数学'
group by c.科目
问题2更新:
update sc
set 成绩=case when sc.成绩 >=90 then 95 when sc.成绩 >=80 then 85 when sc.成绩 >=70 then 75
when sc.成绩 >=60 then 65 else 45 end
from Course c ,sc
where c.C_ID=sc.C_ID and c.科目=N'离散数学'

离散数学的成绩 放在哪个表?