编号 数量 时间
01 100 12/25/2007
01 200 12/26/2007
01 150 01/05/2008
02 100 11/20/2007
02 100 12/21/2007
02 150 01/10/2008
计算时间在12/20/2007到01/01/2008之间的总数量怎么计算?时间取其中一个时间,谢谢!
结果:
01 300 12/25/2007
02 100 12/21/2007
01 100 12/25/2007
01 200 12/26/2007
01 150 01/05/2008
02 100 11/20/2007
02 100 12/21/2007
02 150 01/10/2008
计算时间在12/20/2007到01/01/2008之间的总数量怎么计算?时间取其中一个时间,谢谢!
结果:
01 300 12/25/2007
02 100 12/21/2007
insert into #tt select '01',100,'12/25/2007'
insert into #tt select '01',200,'12/26/2007'
insert into #tt select '01',150,'01/05/2008'
insert into #tt select '02',100,'11/20/2007'
insert into #tt select '02',100,'12/21/2007'
insert into #tt select '02',150,'01/10/2008' select 编号,sum(数量) 数量,convert(varchar(10),min(时间),101)时间 from #tt where 时间 between '12/20/2007' and '01/01/2008' group by 编号
select 编号,sum(数量) from 表名 where 时间>='12/20/2007' and 时间<='01/01/2008' group by 编号
这时间怎么处理?谢谢!
go
insert into a select '01',100,'2007-12-25'
union all
select '01',200,'2007-12-26'
union all
select '01',150,'2008-01-05'
union all
select '02',100,'2007-11-20'
union all
select '02',100,'2007-12-21'
union all
select '02',150,'2008-01-10'
select b.编号,b.数量,b.时间 from
(
select 编号,sum(数量) 数量,min(时间) 时间 from awhere 时间 between '2007-12-20'and '2008-01-01'
group by 编号
) b
drop table a