다음은 해결책입니다.
희망이 있습니다. :)
;with testdata(store,shipntrvl,value)
as
(
select 'abc', 1, 0.56
union all
select 'abc', 5, null
union all
select 'abc', 10, 0.63
union all
select 'abc', 15, null
union all
select 'abc', 20, null
union all
select 'abc', 25, null
union all
select 'abc', 30, 0.96
union all
select 'xyz', 1, 0.36
union all
select 'xyz', 5, 0.38
union all
select 'xyz', 10, null
union all
select 'xyz', 15, 0.46
union all
select 'xyz', 20, null
union all
select 'xyz', 25, null
union all
select 'xyz', 30, 0.91
)
,calc
as
(
select *
,ROW_NUMBER() OVER(partition by store order by shipntrvl) as row_no
from testdata
)
,extra
as
(
select *
,(select top 1 row_no
from calc c2
where c2.row_no < c1.row_no
and c1.value is null
and c2.value is not null
and c1.store = c2.store
order by c2.row_no desc) as prev_nr
,(select top 1 row_no
from calc c2
where c2.row_no > c1.row_no
and c1.value is null
and c2.value is not null
and c1.store = c2.store
order by c2.row_no asc) as next_nr
from calc c1
)
select c.store
,c.shipntrvl
,c.value
,isnull(c.value,
(cnext.value-cprev.value)/
(cnext.shipntrvl-cprev.shipntrvl)*
(c.shipntrvl-cprev.shipntrvl)+cprev.value
) as calculated_value
from calc c
join extra
on extra.row_no = c.row_no
and extra.store = c.store
join calc cnext
on cnext.row_no = case when c.value is null
then extra.next_nr
else c.row_no
end
and c.store = cnext.store
join calc cprev
on cprev.row_no = case when c.value is null
then extra.prev_nr
else c.row_no
end
and c.store = cprev.store
선형 보간이라고 생각합니다. – Paciv
@podiluska .NET에서이 작업을 수행하는 루프가 있으며 동일한 작업을 수행하는 모든 수식이 포함 된 Excel 템플릿도 있습니다. 왜냐하면 간격이 일정하고 특정 간격으로 각각의 값이 알려지기 때문에 Excel은 쉽게 할 수 있다고 생각했습니다. 그러나 접근 방식과 같은 절차를 갖는 것은 내가 시도하고 있지만 가능한 경우 루프가없는 것입니다. 또한 Excel에서 매월 새 행을 추가 할 때 수식을 추가해야하는 문제가 있습니다. – TiredMaster
@Paciv 알 수없는 값은 계산되지만 추정되지는 않습니다. 또한 솔루션은 보간에 대한 계산상의 오버 헤드를 갖는 것보다 훨씬 더 간단 할 수 있다고 생각합니다. 그러나 그것이 무엇을 찾는다 고 생각한다면, 나에게 리드를주십시오. 감사. – TiredMaster