面试题

           胜 负
2015-05-09 2  2

2015-05-10 1  2

  1. create table #tmp (  
  2.     rq varchar(10),  
  3.     shengfu nchar(1)  
  4. )  
  5. --插入数据  
  6. insert into #tmp values('2015-05-09','胜')  
  7. insert into #tmp values('2015-05-09','胜')  
  8. insert into #tmp values('2015-05-09','负')  
  9. insert into #tmp values('2015-05-09','负')  
  10. insert into #tmp values('2015-05-10','胜')  
  11. insert into #tmp values('2015-05-10','负')  
  12. insert into #tmp values('2015-05-10','负')  
  13.   
  14. --查询表中数据  
  15. select * from #tmp  
  16. --查询需要得到的结果  
  17. select rq as ' ',SUM(case when shengfu='胜' then 1 else 0 end) '胜',SUM(case when shengfu='负' then 1 else 0 end) '负'  
  18. from #tmp   
  19. group by rq
原文地址:https://www.cnblogs.com/hello-liyb/p/7764477.html