MySQL中case then用法

1.查询图书价格,若价格为null,则显示unknown,若价格为10到20, 则显示10 to 20

SELECT price,
CASE 
WHEN price='null' THEN 'UnKnow'
WHEN price>10 and price<20 then '10 to 20'
END
FROM book;

 

 

2.

select name,  
 case   
        when birthday<'1981' then 'old'  
        when birthday>'1988' then 'yong'  
        else 'ok' END YORN  
from lee; 

 

 

3.

select NAME,  
 case name  
     when 'sam' then 'yong'  
        when 'lee' then 'handsome'  
        else 'good' end  
from lee; 

 

posted @ 2017-09-21 17:51  4小辣椒1  阅读(624)  评论(0编辑  收藏  举报