我是Presto的新手,正在从事数据清理活动。列的某些条目为NULL。如果找到NULL条目,则转到下一行,直到找到一个值并将其分配给NULL字段。我尝试使用以下查询,但它仅适用于下一行。请让我知道如何遍历该列的所有行,直到满足条件为止。
Data1 Expected result
NULL 100
NULL 100
100 100
200 200
NULL 187
187 187
223 223
456 456
NULL 900
NULL 900
NULL 900
NULL 900
NULL 900
NULL 900
900 900
876 876
Query Used:
case
when (Data1 is NULL and (lead(Data1) OVER (order by A)) IS NOT NULL) then (lead(Data1) OVER (order by A))
else Data1
end
Data Output of the query used
NULL NULL
NULL 100 -------> it worked only when the next row is not null
100 100
200 200
NULL 187 -------> it worked only when the next row is not null
187 187
223 223
456 456
NULL NULL
NULL NULL
NULL NULL
NULL NULL
NULL NULL
NULL 900 -------> it worked only when the next row is not null
900 900
876 876