#if表达式 SELECT reg_no, IF(reg_no='718170554','黄色宾利','红色宾利') FROM car WHERE reg_no IN ('718170554','124553063'); # CASE when SELECT reg_no, CASE reg_no WHEN 718170554 THEN '黄色宾利,沪A55662' WHEN 124553063 THEN '红色宾利,沪A55661' WHEN 114480011 THEN '白色奔驰,沪N55663' WHEN 816053337 THEN '褐色宾利,沪N55665' WHEN 653973365 THEN '银色阿斯顿马丁,沪N55666' WHEN 990125871 THEN '绿色阿斯顿马丁,京B55667' ELSE 'more' END AS testCol FROM car WHERE reg_no IN ('718170554','124553063','114480011','816053337','653973365','990125871'); # IFNULL SELECT IFNULL(NULL,10); SELECT IFNULL(20,10); #if else DELIMITER $$ CREATE PROCEDURE `proc_test`(car_no INT) BEGIN DECLARE reg INT; SELECT reg_no INTO reg FROM car WHERE reg_no=car_no; IF reg = 718170554 THEN SELECT reg,'黄色宾利,沪A55662'; ELSEIF reg = 124553063 THEN SELECT reg,'红色宾利,沪A55661'; ELSEIF reg = 114480011 THEN SELECT reg,'白色奔驰,沪N55663'; ELSEIF reg = 816053337 THEN SELECT reg,'褐色宾利,沪N55665'; ELSE SELECT reg,'E'; END IF; END$$ DELIMITER ; CALL test(718170554); CALL test(816053337);
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/4649.html