SQL Case 的应用

create table test(Date varchar(50) null, Result varchar(50) null) 

insert into test values('1900-1-1','胜')
insert into test values('1900-2-1','胜')
insert into test values('1900-1-1','负')
insert into test values('1900-2-1','负')
insert into test values('1900-1-1','胜')
select * from test


select distinct Date, 
sum(case Result when '胜' then 1 else 0 end) as '胜', 
sum(case Result when '负' then 1 else 0 end) as '负' 
from test 
group by date 


select (case Gender when 1 then '男'
 when 2 then '女' else '其他' end) as Gender from Table1 
原文地址:https://www.cnblogs.com/kevin2013/p/1769720.html