函数创建delimiter $$ -- 创建函数 create procedure avg_calc() begin -- { DECLARE avg DECIMAL(5,2); select avg:avg(result) from (select result from score limit 519) as t; IF avg 70 THEN select * from score where result !100 ORDER BY result desc limit 3; ELSE select * from score ORDER BY result asc limit 3; END IF; end -- } delimiter ; -- 函数调用 call avg_calc();只要有人不及格就全体加 2 分一直加到所有人都≥60 分。delimiter $$ -- 创建函数 create procedure while_calc() begin -- { declare sum_count int; -- 没有通过的数量 select sum_count:count(*) from score where result 60; -- 获取没有通过的数量 WHILE sum_count 0 DO -- 开启循环 select sum_count:count(*) from score where result 60; update score set result result 2 where result 100; END WHILE; select 全员通过; end $$ -- } delimiter ; -- 函数调用 call while_calc(); update score set result 50;case语句select case when result90 then A when result80 then B when result70 then C when result60 then D ELSE E end from score;