发布网友 发布时间:2022-04-24 04:40
共3个回答
热心网友 时间:2022-04-11 18:33
=.=这个不算难题了,不过分有点少....把下面的复制到查询分析器里执行就OK...
--删除table
Drop table #temp
--创建表并插入数据:
create table #temp([ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL
,[SF] varchar(5) null
,[DT] datetime null )
insert into #temp (SF,DT) values ('胜','2006-06-12 00:00:00.000')
insert into #temp (SF,DT) values ('胜','2006-06-12 00:00:00.000')
insert into #temp (SF,DT) values ('负','2006-06-13 00:00:00.000')
insert into #temp (SF,DT) values ('负','2006-06-12 00:00:00.000')
insert into #temp (SF,DT) values ('胜','2006-06-11 00:00:00.000')
insert into #temp (SF,DT) values ('负','2006-06-12 00:00:00.000')
insert into #temp (SF,DT) values ('负','2006-06-13 00:00:00.000')
insert into #temp (SF,DT) values ('胜','2006-06-12 00:00:00.000')
select convert(varchar(10),DT,120) as '时间',count(case when SF='胜' then 1 end)as '胜',count(case when SF='负' then 1 end)as '负'
from #temp
group by convert(varchar(10),DT,120)
order by convert(varchar(10),DT,120)
go
热心网友 时间:2022-04-11 19:51
select a.DT as 日期,a.count(SF) as 胜,b.count(SF) as 负 into 新表
from 旧表 as a,旧表 as b
where a.DT=b.DT and a.SF='胜' and b.SF='负'
group by a.DT
新……
热心网友 时间:2022-04-11 21:26
期待答案