一条SQL查询语句,求代码
create table tb(日期 datetime,TCH int,sdcch real)insert into tb select '2011-12-1',5,5insert into tb select '2011-12-2',14,2insert into tb select '2011-12-4',2,12insert into tb select '2011-12-5',3,2insert into tb select '2011-12-6',5,4go
日期 tch sdcch 2011-12-1 5 52011-12-2 14 22011-12-3 8 72011-12-4 2 122011-12-5 3 22011-12-6 5 4
create table tb(日期 datetime,TCH int,sdcch real)insert into tb select '2011-12-1',5,5insert into tb select '2011-12-2',14,2insert into tb select '2011-12-4',2,12insert into tb select '2011-12-5',3,2insert into tb select '2011-12-6',5,4GOINSERT INTO tb SELECT a.日期+c.number AS 日期, (a.TCH+b.TCH)/2 AS TCH,(a.sdcch+b.sdcch)/2 AS sdcchFROM tb AS a CROSS APPLY (SELECT TOP 1 日期,TCH,sdcch FROM tb WHERE 日期>a.日期 ORDER BY 日期 asc) AS bCROSS JOIN master.dbo.spt_values AS cWHERE NOT EXISTS(SELECT 1 FROM tb WHERE 日期=a.日期+1) AND c.type='P' AND b.日期>a.日期+c.number AND c.number>0