1. 程式人生 > >MySQL中case then用法

MySQL中case then用法

sele null col log clas birt some sql light

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; 

MySQL中case then用法