日期:2014-05-17 浏览次数:20503 次
create table #tmp
(
recordDate varchar(50)
,cl1_40 int
,cl2_60 int
,cl3_70 int
)
insert into #tmp(recordDate,cl1_40,cl2_60,cl3_70)
select '2013-01-01',0, 14, 0
union all select '2013-01-02', 0, 115, 0
union all select '2013-01-03', 0, 128, 0
union all select '2013-01-04', 0, 103, 0
union all select '2013-01-05', 0, 64 ,0
union all select '2013-02-06', 0, 12 ,0
union all select '2013-02-07', 0, 43 ,0
union all select '2013-02-08', 0, 89 ,0
union all select '2013-02-09', 0, 59 ,0
union all select '2013-02-10', 0, 74 ,0
select * from #tmp
select *
,(
select SUM(t1.cl2_60)*1.0/Max(DATEPART(day,t1.recordDate))
from #tmp t1
where t1.recordDate<=t.recordDate
and DATEPART(year,t1.recordDate)= DATEPART(year,t.recordDate)
and DATEPART(MONTH,t1.recordDate)= DATEPART(MONTH,t.recordDate)
) as 'DataOfYouWant'
from #tmp t