流程作业

mysql> 1.创建存储过程,实现从m加到n,显示其和.
mysql> create procedure sp_addmn(m int,n int)
    -> begin
    -> declare s int;
    -> set s=0;
    -> while m<=n
    -> do begin
    -> set s=m+s;
    -> set m=m+1;
    -> end;
    -> end while;
    -> select s as 和;
    -> end#
Query OK, 0 rows affected (0.00 sec)
    -> 2.按照等级进行加分,如果等级为优秀,将其分值按照10%进行提分,最高不超过98分;如果等级为不及格,将其分值按10%进行减分,最低不超过40分.
mysql> create procedure aa(name char(8),cn char(8),g char(8))
    -> begin
    -> declare score real;
    -> set score=(select 成绩 from v_sc where 学生姓名=name and 课程名=cn);
    -> if score>=80 then set g='优秀';
    -> elseif score>=70 and score<80 then set g='良好';
    -> elseif score>=60 and score<70 then set g='及格';
    -> else set g='不及格';
    -> end if;
    -> case
    -> when g='优秀' and  score*1.1<98 then update v_sc set 成绩=成绩*1.1 where
成绩>=80;
    -> when g='良好' or g='及格' or g='不及格' and score*0.9>40 then
    -> update v_sc set 成绩=成绩*0.9;
    -> end case;
    -> select 学生姓名,课程名,成绩,g as 等级 from v_sc
    -> where 学生姓名=name and 课程名=cn;
    -> end#
Query OK, 0 rows affected (0.00 sec)


    -> 3.创建存储过程实现多次加减分.
mysql> create procedure aa(name char(8),cn char(8),g char(8),i int)
    -> begin
    -> declare score real;
    -> declare j int;
    -> set j=1;
    -> set score=(select 成绩 from v_sc where 学生姓名=name and 课程名=cn);
    -> if score>=80 then set g='优秀';
    -> elseif score>=70 and score<80 then set g='良好';
    -> elseif score>=60 and score<70 then set g='及格';
    -> else set g='不及格';
    -> end if;
    -> while j<=i
    -> do begin
    -> case
    -> when g='优秀' and  score*1.1<98 then update v_sc set 成绩=成绩*1.1 where
成绩>=80;
    -> when g='良好' or g='及格' or g='不及格' and score*0.9>40 then
    -> update v_sc set 成绩=成绩*0.9;
    -> set j=j+1;
    -> end case;
    -> end;
    -> end while;
    -> select 学生姓名,课程名,成绩,g as 等级 from v_sc
    -> where 学生姓名=name and 课程名=cn;
    -> end#

 

 

 

 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值