zoukankan      html  css  js  c++  java
  • mysql case....when条件

    oracle的写法
    SELECT decode(ttype,1,’a',2,’b',3,’c',’d') FROM taba

    可以在mysql里写成
    SELECT if(ttype=1, 'a',if(ttype=2,'b', if(ttype =3, 'c', 'd'))) FROM taba

    下面为您举例说明了三种mysql中case when语句的使用方法,供您参考学习,如果您对mysql中case when语句使用方面感兴趣的话,不妨一看。
    
    1。
    
    select name,  
     case   
            when birthday<'1981' then 'old'  
            when birthday>'1988' then 'yong'  
            else 'ok' END YORN  
    from lee; 
    2。
    
    select NAME,  
     case name  
         when 'sam' then 'yong'  
            when 'lee' then 'handsome'  
            else 'good' end  
    from lee; 
    当然了case when语句还可以复合
    
    3。
    
    select name,birthday,  
     case   
         when birthday>'1983' then 'yong'  
            when name='lee' then 'handsome'  
            else 'just so so ' end  
    from lee;  
     
    以上就是mysql中case when语句的使用示例的介绍。
  • 相关阅读:
    阿里云nginx创建多站点
    linux 卸载php mysql apache
    centos php环境搭建
    jquery simple modal
    nodejs 安装express
    nodejs fs.open
    nodejs supervisor
    nodejs 运行
    nodejs shell
    PHP array_pad()
  • 原文地址:https://www.cnblogs.com/mengyuxin/p/5360533.html
Copyright © 2011-2022 走看看