龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 数据库类 > MySQL 技术 >

mysql中case when语句的使用示例

时间:2011-04-12 23:18来源:未知 作者:admin 点击:
分享到:
下面为您举例说明了三种mysql中case when语句的使用方法,供您参考学习,如果您对 mysql 中case when语句使用方面感兴趣的话,不妨一看。 1。 selectname, case whenbirthday '1981'then'old' whenbirthda

下面为您举例说明了三种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语句的使用示例的介绍。

MySQL设置自增字段的方法介绍

常见MySql字段的默认长度

MySQL数值数据类型的范围

MySQL索引类型介绍

mysql添加删除主键的方法


精彩图集

赞助商链接