Use case when statement in mysql

Source: Internet
Author: User
Tags mysql index

The following is an example of how to use the case when statement in mysql for your reference. If you are interested in the use of case when statements in mysql, take a look.

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; 

Of course, the case when statement can be combined.

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.  

The above is an example of how to use the case when statement in mysql.

How to Set auto-increment fields in MySQL

Default length of common MySql Fields

Range of MySQL numeric data types

MySQL index type

How to add or delete a primary key in mysql

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.