• mysql if条件


    #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);
    

      

  • 相关阅读:
    【转】Google 的眼光
    【转】不要去SeaWorld
    【转】Tesla Autopilot
    【转】Tesla Model X的车门设计问题
    【转】Tesla Model S的设计失误
    【转】编程的智慧
    【转】智商的圈套
    【转】创造者的思维方式
    【转】恶评《星际穿越》
    【转】谈创新
  • 原文地址:https://www.cnblogs.com/simpledev/p/4191792.html
Copyright © 2020-2023  润新知