胜 负
2015-05-09 2 2
2015-05-10 1 2
- create table #tmp (
- rq varchar(10),
- shengfu nchar(1)
- )
- --插入数据
- insert into #tmp values('2015-05-09','胜')
- insert into #tmp values('2015-05-09','胜')
- insert into #tmp values('2015-05-09','负')
- insert into #tmp values('2015-05-09','负')
- insert into #tmp values('2015-05-10','胜')
- insert into #tmp values('2015-05-10','负')
- insert into #tmp values('2015-05-10','负')
- --查询表中数据
- select * from #tmp
- --查询需要得到的结果
- select rq as ' ',SUM(case when shengfu='胜' then 1 else 0 end) '胜',SUM(case when shengfu='负' then 1 else 0 end) '负'
- from #tmp
- group by rq