SQL case when then else end 组合用法~
在数据表设计的时候,我们经常会用到bit,int等字段来表示一些值,例如下面表中我们性别列用 0表示男,1表示女
正常查询效果 
select * from table
| Id | Name | Gender | 
| 1 | 张三 | 0 | 
| 2 | 李四 | 1 | 
我们想要的效果
 
select Id as 编号, Name as 姓名, case then Gender=0 when '男' then Gender=1 '女' else '未知' end as 性别
from table 或者 select Id as 编号, Name as 姓名, case then Gender=0 when '男' else '女' end as 性别from table
| 编号 | 姓名 | 性别 | 
| 1 | 张三 | 男 | 
| 2 | 李四 | 女 | 
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号