我知道有很多解决方案,但不幸的是我无法使用分区或关键字TOP。我在之前的帖子中没有尝试过任何作品。
我想要的结果是当任何完成百分比为NULL时,它应该从上一个非值完成百分比中获取值,如下所示:
答案 0 :(得分:3)
使用outer apply
:
select t.projectname, t.sequence,
coalesce(t.completion_percentage, t2.completion_percentage) as completion_percentage
from t outer apply
(select top 1 t2.*
from t t2
where t2.projectname = t.projectname and
t2.completion_percentage is null and
t2.sequence < t.sequence
order by t2.sequence desc
) t2;
答案 1 :(得分:0)
你可以试试这个:
SELECT t2.project_name,t2.sequence,
case when percentage is null then (select percentage from table1 t1 where t1.sequence=t2.sequence-1 )
else t2.percentage end as percentage
FROM table t2