我正在尝试根据两列的组合对表中的列进行uodate。如果值为null,则从开始时间开始我将其设置为0,否则我将其设置为最大值,直到该日期为止。我是使用SQL SERVER 2008.Thanks提前获得帮助!
update Table1
set value = a.value
from
( SELECT product,
week ,
case when value is null then
(case when max(value) over(PARTITION BY product ORDER BY week ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) is null then 0
else (max(value) over (PARTITION BY product ORDER BY week ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)) end )
else value end as value
from table2 ) a
where a.product = table1.product
and a.week = table1.week
答案 0 :(得分:1)
2012年ROWS
子句中添加了OVER
关键字。您将无法在2008年使用该关键字。
https://msdn.microsoft.com/en-us/library/ms189461(v=sql.110).aspx