Вы можете использовать обновляемые CTE и оконные функции:
with toupdate as (
select t.*, lag(current) over (order by datetime) as prev_current,
lead(current) over (order by datetime) as next_current
from t
)
update toupdate
set current = 0
where current is null and (prev_current is not null or next_current is not null);
Если вам просто нужен дополнительный столбец в запросе select
(в отличие от изменения данных), тогда:
with t as (
select t.*, lag(current) over (order by datetime) as prev_current,
lead(current) over (order by datetime) as next_current
from t
)
select t.*,
(case when current is null and (prev_current is not null or next_current is not null)
then 0 else current
end) as new_current
from t;