我知道有很多解决方案,但不幸的是我无法使用分区或关键字TOP。我在之前的帖子中没有尝试过任何作品。
我的表格如下:
我想要的结果是当任何完成百分比为NULL
时,它应该从上一个非值完成百分比中获取值,如下所示:
我尝试了这个查询,但没有任何效果。你能告诉我哪里出错了吗?
SELECT sequence,project_for_lookup,
CASE WHEN completion_percentage IS NOT NULL THEN completion_percentage
ELSE
(SELECT max(completion_percentage) FROM [project_completion_percentage] AS t2
WHERE t1.project_for_lookup=t2.project_for_lookup and
t1.sequence<t2.sequence and
t2.completion_percentage IS NOT null
END
FROM [project_completion_percentage] AS t1
答案 0 :(得分:1)
SQL Server 2008不支持累积窗口功能。所以,我建议file_get_contents
:
outer apply
答案 1 :(得分:0)
这有用吗?对我来说似乎。你错过了一个括号,并且顺序倒退了。
http://sqlfiddle.com/#!3/465f2/4
SELECT sequence,project_for_lookup,
CASE WHEN completion_percentage IS NOT NULL THEN completion_percentage
ELSE
(
SELECT max(completion_percentage)
FROM [project_completion_percentage] AS t2
WHERE t1.project_for_lookup=t2.project_for_lookup
-- sequence was reversed. You're on the row t1, and want t2 that is from a prior sequence.
and t2.sequence<t1.sequence
and t2.completion_percentage IS NOT null
--missing a closing paren
)
END
FROM [project_completion_percentage] AS t1