mysql中case when语句的使用示例


  本文标签:mysql中case when

  下面为您举例说明了三种mysql中case when语句的使用方法,供您参考学习,如果您对mysql中case when语句使用方面感兴趣的话,不妨一看  。

  1  。

  1. select name,  
  2.  case   
  3.         when birthday<1981 then old  
  4.         when birthday>1988 then yong  
  5.         else ok END YORN  
  6. from lee; 

  2  。

  1. select NAME,  
  2.  case name  
  3.      when sam then yong  
  4.         when lee then handsome  
  5.         else good end  
  6. from lee; 

  当然了case when语句还可以复合

  3  。

  1. select name,birthday,  
  2.  case   
  3.      when birthday>1983 then yong  
  4.         when name=lee then handsome  
  5.         else just so so  end  
  6. from lee;  
  7.  

  以上就是mysql中case when语句的使用示例的介绍  。