34,870
社区成员




SET NOCOUNT ON
create TAble A (col1 float, col2 float)
insert A (col1)
select 1
union all select 2
union all select 3
union all select 4
union all select 5
GO
With Ac (rowID, col1, col2)
AS
( Select row_number() over(order by Current_TimeStamp) as rowID, col1, col2
From A
)
select (select sum(col1) from Ac where rowID <= Ac1.rowID) as col1,
CASE WHEN rowid= 1 THEN (select sum(col1)/2 from AC where rowID <=2)
WHEN rowID = (select max(rowID) from Ac) THEN (select sum(col1)/2 from AC where
rowID >= Ac1.rowID-1)
ELSE (select sum(col1/3) from AC where rowID >= Ac1.rowID-1 AND rowID <= Ac1.rowID+1)
END as col2
FROM Ac Ac1
drop table A