DELIMITER //
create procedure add_count(in idx int,in sum int) --传入两个参数,一个为学生的ID,一个为成绩
begin
declare sum1 int;
if sum = 59 then --如果分数为59,那么加1
set sum1 = sum + 1;
update tb_name set 成绩 = sum1 where id = idx;
end fi;
end //
DELIMITER ;
或者更新语句可以直接写成update tb_name set 成绩 = 60 where id = idx;
update tbname set 成绩=成绩+1 where 成绩=59 and 班级=‘满足条件的班级’
如果成绩表中没有直接的班级字段,那么可以这样:
update tbname set 成绩=成绩+1 where 成绩=59 and exists(select 班级 from 学生表 where 学生表.学生号=成绩表.学生号 and 学生表.班级=‘满足条件的班级’)