mysql中case的用法
#mysql中CASE的用法
#CASE的用法
DELIMITER $
CREATE PROCEDURE p11(in score INT)
BEGIN
CASE
WHEN score >=90 AND score <= 100 THEN SELECT '优秀';
WHEN score >= 80 THEN SELECT '良好';
WHEN score >= 60 THEN SELECT '及格';
ELSE SELECT '不及格';
END CASE;
END$
#
CALL p11(92);
CALL p11(89);
CALL p11(78);
CALL p11(65);
CALL p11(52);
#CASE的用法
DELIMITER $
CREATE PROCEDURE p12(in scoreLevel VARCHAR(10))
BEGIN
CASE scoreLevel
WHEN 'A' THEN SELECT '优秀';
WHEN 'B' THEN SELECT '良好';
WHEN 'C' THEN SELECT '及格';
ELSE SELECT '不及格';
END CASE;
END$
#
CALL p12('A');
CALL p12('B');
CALL p12('C');
CALL p12('H');
CALL p12('W');