日期:2014-05-18 浏览次数:20619 次
create table tb(日期 datetime,TCH int,sdcch real) insert into tb select '2011-12-1',5,5 insert into tb select '2011-12-2',14,2 insert into tb select '2011-12-4',2,12 insert into tb select '2011-12-5',3,2 insert into tb select '2011-12-6',5,4 go
日期 tch sdcch 2011-12-1 5 5 2011-12-2 14 2 2011-12-3 8 7 2011-12-4 2 12 2011-12-5 3 2 2011-12-6 5 4
create table tb(日期 datetime,TCH int,sdcch real) insert into tb select '2011-12-1',5,5 insert into tb select '2011-12-2',14,2 insert into tb select '2011-12-4',2,12 insert into tb select '2011-12-5',3,2 insert into tb select '2011-12-6',5,4 GO INSERT INTO tb SELECT a.日期+c.number AS 日期, (a.TCH+b.TCH)/2 AS TCH,(a.sdcch+b.sdcch)/2 AS sdcch FROM tb AS a CROSS APPLY (SELECT TOP 1 日期,TCH,sdcch FROM tb WHERE 日期>a.日期 ORDER BY 日期 asc) AS b CROSS JOIN master.dbo.spt_values AS c WHERE NOT EXISTS(SELECT 1 FROM tb WHERE 日期=a.日期+1) AND c.type='P' AND b.日期>a.日期+c.number AND c.number>0